DefaultView (yes or no)

Roey

Well-known member
Joined
Oct 10, 2002
Messages
238
Location
Canada
Might be a bit of a silly question but what the hell. What is the correct method for binding data ?

Me.combobox1.DataSource = Me.dataset.Tables("Table1")

or

Me.combobox1.DataSource = Me.dataset.Tables("Table1").DefaultView


They both seem to produce the same results except that the DefaultView method allows you to sort the data etc.

So if I dont need to sort the data should I use defaultview or not or doesnt it matter...

Thanks
 
The first way, you are binding to a datatable.
The second, you are binding to a dataview.
"A major function of the DataView is to allow data binding on both Windows Forms and Web Forms.

Additionally, a DataView can be customized to present a subset of data from the DataTable. This capability allows you to have two controls bound to the same DataTable, but showing different versions of the data. For example, one control may be bound to a DataView showing all of the rows in the table, while a second may be configured to display only the rows that have been deleted from the DataTable. The DataTable also has a DefaultView property which returns the default DataView for the table. For example, if you wish to create a custom view on the table, set the RowFilter on the DataView returned by the DefaultView."
 
The forms that I am talking about display all the data from a DataTable, and I wondered if it was good practice to add the DefaultView onto the DataTable without any filtering or just leave the datasource bound to the table.

My thoughts where that you should always add .DefaultView to the datatable name in case at a later date you wanted to do some sort of filtering within that form. However I wasnt sure if I was correct in my thinking.

Please let me know if I have misunderstood this concept... as it wouldnt be the first time
 
Back
Top