Hi all!
I have a VB app with SQL Server 2005 db. On my main form I have a DataGridView and a few labels for Master/Detail purposes, which are all bound to MyBindingSource (no binding navigator). I have chosen to not allow the user to delete, add or edit from the Grid for certain reasons...hence the (read-only) labels for the Details. Any adding or editing will be done via another Dialog box. Any deleting will be executed via a button above the Grid.
My add/edit dialog is a generic form, ie it has a "FormMode", so if I hit the "Add New" button it will show the form with all textboxes, dateTimePickers, etc being empty. If I select a row and hit the "Edit" button or double-click on the row, the FomMode of my dialog changes, and I pass through the primary key as an Integer. So in the Load event, I do a select based on the Integer passed in, and fill the textboxes, etc accordingly. Sorry if Im being elementary here with my descriptions, but just want to paint a complete picture.
My question is this:
Whether I delete, add or edit any of the rows' data, I want to know what is the most efficient way of refreshing the datagridview? I know that MyBindingSource.ResetBindings(false) won't work, as the input controls on my dialog form are unbound. Anyway after the line of code that i use to delete a row, I call a procedure where i clear the tableadapter and then "re-fill" it. I do a similar thing for Adding and Editing. This method does work now as I have only 5 or so rows of data that I'm testing with. But my Database table is going to grow. So performance will become an issue if I have to keep making the Fill method call. Is there a better, more efficient way of doing what I want?
FYI: For editing, I am opening the above-mentioned dialog box and my code flows as:
I know this is not very efficient, so please could someone shed some light on this for me. Cjard, if u r reading this post also, I hold in high regard any advice u have.
Thank u very much!
rgdz
Shalan
I have a VB app with SQL Server 2005 db. On my main form I have a DataGridView and a few labels for Master/Detail purposes, which are all bound to MyBindingSource (no binding navigator). I have chosen to not allow the user to delete, add or edit from the Grid for certain reasons...hence the (read-only) labels for the Details. Any adding or editing will be done via another Dialog box. Any deleting will be executed via a button above the Grid.
My add/edit dialog is a generic form, ie it has a "FormMode", so if I hit the "Add New" button it will show the form with all textboxes, dateTimePickers, etc being empty. If I select a row and hit the "Edit" button or double-click on the row, the FomMode of my dialog changes, and I pass through the primary key as an Integer. So in the Load event, I do a select based on the Integer passed in, and fill the textboxes, etc accordingly. Sorry if Im being elementary here with my descriptions, but just want to paint a complete picture.
My question is this:
Whether I delete, add or edit any of the rows' data, I want to know what is the most efficient way of refreshing the datagridview? I know that MyBindingSource.ResetBindings(false) won't work, as the input controls on my dialog form are unbound. Anyway after the line of code that i use to delete a row, I call a procedure where i clear the tableadapter and then "re-fill" it. I do a similar thing for Adding and Editing. This method does work now as I have only 5 or so rows of data that I'm testing with. But my Database table is going to grow. So performance will become an issue if I have to keep making the Fill method call. Is there a better, more efficient way of doing what I want?
FYI: For editing, I am opening the above-mentioned dialog box and my code flows as:
VB.NET:
Dim myDialog as new frmAddEdit
With myDialog
[INDENT].formMode = myMode.Edit[/INDENT]
[INDENT].rowID = DataGridView.SelectedRows.Item(0).Cells(0).Value[/INDENT]
[INDENT].ShowDialog()[/INDENT]
End With
myTableAdapter.ClearBeforeFill = True
myTableAdapter.Fill(myDataSet.myTable)
I know this is not very efficient, so please could someone shed some light on this for me. Cjard, if u r reading this post also, I hold in high regard any advice u have.
Thank u very much!
rgdz
Shalan