DataTable, BindingSource and DataGridView

DataTable, BindingSource and DataGridView

Post by Eric B » Thu, 20 Nov 2008 08:23:44

I could use a little clarification on using a BindingSource with my
DataTable. As I understand it, the BindingSource sits between my data source
(a DataTable) and DataGridView and any changes made to it is reflected in
the other two?

Now if that is so, how should I access the elements of my DataTable? I need
to make decisions on what Rows to remove based on comparing the values of
the elements. Should I access the individual elements via the DataTable,
DataGridView cell values, or am I missing a member in my BindingSource
object that allows me to retrieve and/or modify individual element values?


Eric B.

DataTable, BindingSource and DataGridView

Post by Nicholas P » Thu, 20 Nov 2008 23:28:00


The BindingSource class was introduced because people were used to
having the notion of a "current" record combined ^with^ the data set.

You can access the current values of the "row" in the BindingSource
through the indexer (the same way you would with a DataRow).

If you need to cycle through the rows, you can use the MoveFirst,
MoveNext, MoveLast, MovePrevious methods to navigate through the data.

If the possibility of the type of the underlying data source might
change, from a design standpoint, it would be better to work with the
BindingSource, since that is abstracting the underlying data type.

However, if the underlying data source type is "baked", meaning it will
not change, then work with the data set.

I will typically construct my own DataView when working with a DataTable
and I need to perform specific sorting or filtering. If I don't have a need
for that, then I access the DataSet directly.

- Nicholas Paldino [.NET/C# MVP]


DataTable, BindingSource and DataGridView

Post by Eric B » Sat, 22 Nov 2008 04:03:12

"Nicholas Paldino [.NET/C# MVP]" < XXXX@XXXXX.COM > wrote in

Thank you very much for the explanation. :D

Eric B.