Updating Datagrid Cell Value
-
Hi All, This probably really easy for somebody out there but this problem is doing my head in! What i want to do is update a a single cell in a in a datarow of a datagrid with a value from a textbox so i don't have use a query to repopulate the datagrid after a update query. What i've tried Updating the DataTable or DataSet from the datagrid before updating with the following code: 1)
mydatatable.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
2)ds.Tables[0].Columns[0].Table.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
and then rebind it to the datagrid. My problem is that the "ItemArray.SetValue" method doesn't seem to be updating the value when i check it through the step through debugging. Please help, Thanks in advance confused -
Hi All, This probably really easy for somebody out there but this problem is doing my head in! What i want to do is update a a single cell in a in a datarow of a datagrid with a value from a textbox so i don't have use a query to repopulate the datagrid after a update query. What i've tried Updating the DataTable or DataSet from the datagrid before updating with the following code: 1)
mydatatable.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
2)ds.Tables[0].Columns[0].Table.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
and then rebind it to the datagrid. My problem is that the "ItemArray.SetValue" method doesn't seem to be updating the value when i check it through the step through debugging. Please help, Thanks in advance confusedDont play with the itemarry. It is handled internally. mydatatable.Rows[lastUpdatedRecord] = int.Parse(txtVal.Text); will do the job. Live Life King Size Alomgir Miah
-
Dont play with the itemarry. It is handled internally. mydatatable.Rows[lastUpdatedRecord] = int.Parse(txtVal.Text); will do the job. Live Life King Size Alomgir Miah
Thank you for your response. My problem is this:
mydatatable.Rows[lastUpdatedRecord] = "Needs Type DataRow"
DataRow is made up of a array of values, a single value in the array represents a single cell value in the datarow. I just need to update a single cell value in the datarow array. Is there any other way of updating the datagrid without having to query the database? Thanks in advance, -
Thank you for your response. My problem is this:
mydatatable.Rows[lastUpdatedRecord] = "Needs Type DataRow"
DataRow is made up of a array of values, a single value in the array represents a single cell value in the datarow. I just need to update a single cell value in the datarow array. Is there any other way of updating the datagrid without having to query the database? Thanks in advance,With just one indexer (
lastUpdatedRecord
) you reference a single row, but when you use 2 indexers, you can access a single cell:mydatatable.Rows[lastUpdatedRecord][columnNumber] = newValue;
Regards, mav -
With just one indexer (
lastUpdatedRecord
) you reference a single row, but when you use 2 indexers, you can access a single cell:mydatatable.Rows[lastUpdatedRecord][columnNumber] = newValue;
Regards, mav