Main Page | Report this Page
 
.NET DotNet Forum Index  »  ADO .NET Forum  »  Can't add row to datagridview?...
Page 1 of 1    

Can't add row to datagridview?...

Author Message
Grant Schenck...
Posted: Tue Oct 13, 2009 6:44 pm
Guest
Hello,

I'm trying to programmatically add a row to a SQL bound (via binding source)
to a datagridview.

The code is as follows:

DataRowView drView =
(DataRowView)stationBindingSource.AddNew();
STPSRecorderDataSet.StationRow stationRow =
(STPSRecorderDataSet.StationRow)drView.Row;
stationRow.Extension = strExtensionToAdd;

It works fine and if I add more then one row they show up.

Now the problem is that if I move to a different record and then move back
the last row I added is removed. Also, if before selecting a different
record I manually select another row in the view, then, when I come back the
record does not disappear.

Does the code above look correct for adding a row to a bound DGV? Why does
the last row not "stick"?

--
Grant Schenck
 
Scott M....
Posted: Thu Oct 15, 2009 9:54 am
Guest
"Grant Schenck" <schenckg at (no spam) optonline.net> wrote in message
news:ecACwdGTKHA.4324 at (no spam) TK2MSFTNGP05.phx.gbl...
Quote:
Hello,

I'm trying to programmatically add a row to a SQL bound (via binding
source) to a datagridview.

The code is as follows:

DataRowView drView =
(DataRowView)stationBindingSource.AddNew();
STPSRecorderDataSet.StationRow stationRow =
(STPSRecorderDataSet.StationRow)drView.Row;
stationRow.Extension = strExtensionToAdd;

It works fine and if I add more then one row they show up.

Now the problem is that if I move to a different record and then move back
the last row I added is removed. Also, if before selecting a different
record I manually select another row in the view, then, when I come back
the record does not disappear.

Does the code above look correct for adding a row to a bound DGV? Why
does the last row not "stick"?

--
Grant Schenck

It seems to me that you are adding the row correctly, but then the DGV is
just rebinding to its original data source. What I would do is add the data
that was placed into the DGV into the underlying data source and when the
DGV attempts to rebind, you'll have the new data in the grid.

-Scott
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sun Nov 22, 2009 5:57 am