Desperately seeking ability to add a new row in my DataGridView.


G

Guest

I have a dataset that is filled from a SQL backend using stored procedures.
I display the data with a data bound DataGridView and a binding source
object. I can update and delete any row I want but every time I add a new
row using the new row in the DataGridView it adds it but when I switch rows
it disappears. I do a search of the data and the row is defiantly not added
to the dataset. I use DefaultValuesNeeded event to add a default value to
every column but my row still just disappears once you switch rows. What am
I missing? Do I have to add the row to the dataset myself; I thought the
DataGridView and the binding source took care of this? Can someone point me
to an example to look at? I have not found anything in my searching to help
me figure out my problem.

Also once I call the update method of my data adapter and it inserts the new
row in the database how do I get my stored procedure to return the row ID for
the row that was just added and add the row ID to the correct row in my
dataset?

Any help would be appreciated.

Thanks…
Drew
 
Ad

Advertisements

S

Scott Willis

One error that can cause this is setting a non-string default value, e.g.:
e.Row.Cells["xColumn"].Value = 0;
This gave me no compiler errors or warnings, but caused the newly-added row to disappear. Corrected by writing a string value instead:
e.Row.Cells["xColumn"].Value = "0";

Best regards,
Scott




Dre wrote:

Desperately seeking ability to add a new row in my DataGridView.
27-Aug-07

I have a dataset that is filled from a SQL backend using stored procedures.
I display the data with a data bound DataGridView and a binding source
object. I can update and delete any row I want but every time I add a new
row using the new row in the DataGridView it adds it but when I switch rows
it disappears. I do a search of the data and the row is defiantly not added
to the dataset. I use DefaultValuesNeeded event to add a default value to
every column but my row still just disappears once you switch rows. What am
I missing? Do I have to add the row to the dataset myself; I thought the
DataGridView and the binding source took care of this? Can someone point me
to an example to look at? I have not found anything in my searching to help
me figure out my problem

Also once I call the update method of my data adapter and it inserts the new
row in the database how do I get my stored procedure to return the row ID for
the row that was just added and add the row ID to the correct row in my
dataset

Any help would be appreciated

Thanks??
Drew

Previous Posts In This Thread:

Desperately seeking ability to add a new row in my DataGridView.
I have a dataset that is filled from a SQL backend using stored procedures.
I display the data with a data bound DataGridView and a binding source
object. I can update and delete any row I want but every time I add a new
row using the new row in the DataGridView it adds it but when I switch rows
it disappears. I do a search of the data and the row is defiantly not added
to the dataset. I use DefaultValuesNeeded event to add a default value to
every column but my row still just disappears once you switch rows. What am
I missing? Do I have to add the row to the dataset myself; I thought the
DataGridView and the binding source took care of this? Can someone point me
to an example to look at? I have not found anything in my searching to help
me figure out my problem

Also once I call the update method of my data adapter and it inserts the new
row in the database how do I get my stored procedure to return the row ID for
the row that was just added and add the row ID to the correct row in my
dataset

Any help would be appreciated

Thanks??
Drew

EggHeadCafe - Software Developer Portal of Choice
Internet Explorer 8 Beta 2 on Virtual PC 2007
http://www.eggheadcafe.com/tutorial...e0-a8278cba76ab/internet-explorer-8-beta.aspx
 
Ad

Advertisements

S

Scott Willis

To clarify: for a DataGridViewTextBoxColumn, the expected Value data type is a string. It appears that if you write some other data type (such as int) to the Value, no error is indicated but the row will disappear or otherwise misbehave.



Scott Willis wrote:

Check your default values
27-Oct-09

One error that can cause this is setting a non-string default value, e.g.:
e.Row.Cells["xColumn"].Value = 0;
This gave me no compiler errors or warnings, but caused the newly-added row to disappear. Corrected by writing a string value instead:
e.Row.Cells["xColumn"].Value = "0";

Best regards,
Scott

Previous Posts In This Thread:

EggHeadCafe - Software Developer Portal of Choice
Pete's Real Jewish Nuclear Bomb Holiday Chili
http://www.eggheadcafe.com/tutorial...da-26bad47324de/petes-real-jewish-nuclea.aspx
 

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