I've been looking at the code samples for binding data to a DataGridView
using the bindingSource property.
I do somthing like
bindingSource = new BindingSource();
dataGridView.DataSource = bindingSource;
Refresh();
private void Refresh()
{
DataTable t = GetDataTable( mySQLStmt );
bindingSource.DataSource = t;
}
My problem is that the binding only points the DataGridView to an instance
of the data when the Refresh( ) is performed. After the refresh is performed
the binding is broken. If the data in my database changes I have to call
refresh again. This is relatively slow. There isn't a permanent binding
between the grid and the data. It’s more like the grid shows a snapshot in
time.
I want to display a grid and then allow data in that grid to be changed
through some edit controls in the UI (or even changing the cells in the
grid), however this mechanism isn’t really binding the grid to the database
all its doing is saying at some instance in time manually update the grid.
In VB6 I used to use a datacontrol, bind the grid to the datacontrol, If I
changed the underlying data through an edit control bound to the datasource
the grid would update instantaneously, I didn’t need to perform a refresh the
grid was permanently bound to my data and reflected whatever happened to my
data.
Is this possible in .NET 2.0?
TIA
Bart Mermuys - 16 Oct 2005 14:04 GMT
Hi,
> I've been looking at the code samples for binding data to a DataGridView
> using the bindingSource property.
[quoted text clipped - 19 lines]
> between the grid and the data. It's more like the grid shows a snapshot in
> time.
DB <-> DataTable <-> DataGridView
There is a permanent binding between the DataTable and the DataGridView but
there is no permanent binding between the DataTable and the DB, because
ADO.NET uses a disconnected model.
If a TextBox is bound to the same DataTable as a DataGridView and you change
the TextBox then the DataTable will change and also the DataGridView, but
not the DB. The DB will only be updated when you use DataAdapter.Update.
If it possible you should prefer this way, because it's more scalable.
If you really want a connected model then as far as i know there is little
(or even no) support for this in ADO.NET, do a google search on "+ADO.NET
+connected" or re-ask your question in
"microsoft.public.dotnet.framework.adonet".
HTH,
Greetingss
> I want to display a grid and then allow data in that grid to be changed
> through some edit controls in the UI (or even changing the cells in the
[quoted text clipped - 14 lines]
>
> TIA