DataTable, BindingSource and DataGridView

E

Eric B.

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?

TIA

Eric B.
 
N

Nicholas Paldino [.NET/C# MVP]

Eric,

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.
 
E

Eric B.

Nicholas Paldino said:
Eric,

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]
- (e-mail address removed)

Eric B. said:
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?

TIA

Eric B.

Thank you very much for the explanation. :D

Eric B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top