I've linked a Microsoft Access database to my Visual Studio project and using the data sources I have included a data grid view to modify the data. When I dragged and dropped the data grid view onto my project it automatically added the tool strip but when I try to save the modified data by pressing the save icon it won't save it permanently, meaning I can't close the program and re-open it with the same changes.
I looked at the code for the save button and even changed it to the official Microsoft support page code so it displays a message if it saves successfully and if not, however even though it's telling me it's saved correctly when I re-open the project no changes has been saved?
Here's the code for the save button I have so far:
private void modulesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.modulesBindingSource.EndEdit();
this.modulesTableAdapter.Update(this.modulesDatabaseDataSet.Modules);
MessageBox.Show("Saved succesfully","Save Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show("Unable to save. Make sure all modified data is the correct data type.","Save Failed",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
Related
I'm developing a PDF creator using Windows Forms application in Visual Studio Community 2017. I'm using MigraDoc to generate PDFs and they are directly created by a series of data inserted by the user in textboxes.
The page for inserting and displaying the data is the same, because I want a real time update of the PDF document preview. To display the PDF I'm using an axAcroPDF element obtained in the COM section after the installation of Adobe Reader.
In order to update the PDF document I have written a class that simply introduces the new elements (I use a Leave event trigger on textboxes to call the update) and load the new PDF file inside the axAcroPDF element:
axAcroPDF1.LoadFile(filename);
The problem is the fact that each time I insert new data in one of the textboxes and the leave event is triggered it is like the entire form is reloaded and I lose focus on the textbox I was writing on (data inserted remains but the focus gets totally lost and the writing cursor is not preserved). This happens to the other textboxes if I click on another one or if I use tab to move to the next one. Notice that the PDF is correctly updated. Is there any method to avoid this problem and update the PDF section without losing focus on textboxes? Is it also possible doing that on a changetext event listener for those textboxes?
Here is an extract of the code use. The function updateText is called when a changetext event is detected on the textbox:
private void updateText(object sender, EventArgs e)
{
updateDocument();
axAcroPDF1.LoadFile(filename);
TextBox s = (TextBox)sender;
s.Focus();
}
I have been trying to save an open excel workbook and have not been able to.I am using Visual Studio to write a program in c#. I have a windows Userform which when launches, open an excel document in a webBrowser within the form. On that userform, I created a Save button as I would like to save the changes made to the excel.
My code to open excel in webbrowser is:
private void Excelform_Load(object sender, EventArgs e)
{
// Application.DoEvents();
if (File.Exists(m_ExcelFileName))
{
webBrowser1.Navigate(m_ExcelFileName, false);
}
}
This works fine.
HOWEVER when I try to save the changes to the file I either get an error (File in or OR Operation not Executed). Tried webBrowser1.ShowSaveAsDialog(); but this requires user interaction. All I want is when the user click on the save_btn the file saves.
SO can anyone help be figure out how to save the changes made to an excel file that is currently open in a webBrowser on a userform?
Right now this is all I have:
private void toolStripButton3_Click(object sender, EventArgs e)
{
try
{
webBrowser1.ShowSaveAsDialog();
}
catch (Exception ex)
{
// Not updated
MessageBox.Show(ex.Message);
}
}
HELP PLEASE :(
I am trying to edit treeview node names in a treeview (they become editable on a button click ) and then I want them to remain saved (if I exit and enter the aplication again, the new, edited names should be displayed), BUT they always revert to the original name(text) on program reentering.
private void button1_Click(object sender, EventArgs e)
{
treeView1.LabelEdit = true;
}
Questions is how to make the new treeview node names be saved after editing, so when I enter the aplication again they don't reset to the old ones.
You can use the event on application shutdown to manually iterate over the TreeView and save the data to a file. Then when you applications starts again read them and populate the TreeView.
You cannot edit your project by modifying the developped program runtime.
I have a WindowsForm project that is running two BackgroundWorker objects for testing if data should be collected and the collection of the data. These seem to run ok, but when I add the functionality to look at the data collected, the form freezes upon trying to graph the data available.
When clicking the first button the data is listed in a new form window with list boxes. On this new window I have another button that is for graphing the data if it seems ok.
This is where the whole project freezes. I have tried instead of soft copying the class reference that I pass into the new form, making a new object within the constructor. And as long as the data collection BackgroundWorker is not running, it appears to be working ok. When the collection is happening, clicking the plot button freezes the form, the data show button works just fine.
private void wellStatusButton1_Click(object sender, EventArgs e)
{
try
{
ListDataForm temp = new ListDataForm(tubes[0], 1);
temp.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void plotDataButton_Click(object sender, EventArgs e)
{
try
{
GraphForm plotData = new GraphForm(at);
plotData.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
It is hard to get much information from your question, but one thing that might be useful to you is this: When a windows program is doing something else in the background, usually the UI may be frozen. You can try using: Application.DoEvents() periodically, that will allow the UI to appear more responsive.
private void RevenueSummary_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'accountingDataSet1.Revenue' table. You can move, or remove it, as needed.
this.revenueTableAdapter.Fill(this.accountingDataSet1.Revenue);
string strGEC = GEClabel.Text;
fillByToolStripButton.PerformClick();
}
hi, I am having problems displaying the data after I add a new revenue item. It will be display in the database but not in the datagridview. It will only appear if I close the application and run it again.
As i can see in your code you are calling the fill method only when the form is Loaded (I am assuming RevenueSummary_Load method is to handle the load event of the form), this makes the accountingDataSet1 to be filled only when your Form is loaded and thats why when you update the database its not reflected in the dataset.
There are two things you can do to solve this.
1) Employ a ServiceBroker that will notify your application when the database is updated via SqlDependency (I assume your Database has this facility).
2) The other simple method would be have a refresh button where you fill the dataset again.
3) Finally you can have a timer that fills the dataset on every interval
NOTE: Both SQL Server and Oracle support Change Data Capture.
Update
I dont know if MS Access has any push notification feature. As i have searched over internet your only options are either to go with timer based database polling or Implement a FileSystemWatcher object to monitor whether your MS Access database file gets changed.
here is an example to this approach.