Steven:
Framework 1.1
Assigning a value by using this statement "dataGrid1[3,5]
= "test";" works but I can not seem to get the
sqlDataAdapter to recognize that changes were made to the
row unless the cursor is move from that cell. With the
following code.
if(dataSet21.HasChanges())
sqlDataAdapter4.Update(dataSet21,"TableName");
Therefore, I tried the following code which still did not
cause the dataSet21.HasChanges() to return true and also
updated the wrong row since the dataView sort changes the
order of the dataGrid but not the table. ( guess that is
the explaination. )
rowNum = dataGrid1.CurrentCell.RowNumber;
// Get the selected DataGridColumnStyle.
DataGridColumnStyle dgCol;
dgCol = dataGrid1.TableStyles[0].GridColumnStyles
["AColumnName"];
//
Invoke the BeginEdit method to see if editing can begin.
if
(dataGrid1.BeginEdit(dgCol, rowNum))
{
// Edit row value. Get the DataTable and selected
row.
DataTable myTable;
DataRow myRow;
// Assuming the DataGrid is bound to a DataTable.
myTable = (DataTable)dataSet21.Tables[0];
myRow = myTable.Rows[rowNum];
// Invoke the Row object's BeginEdit method.
myRow.BeginEdit();
myRow["AColumnName"] = "New Value";
// You must accept changes on both DataRow and
DataTable.
myRow.AcceptChanges();
myTable.AcceptChanges();
dataGrid1.EndEdit(dgCol, rowNum, false);
}
I guess the real question is --once the dataGrid cell is
assigned an new value, how do I signal the dataSet that
there was a change so that an update can occur?
----- Original Message-----
I tested this by binding a datagrid to a dataview on the Northwind
Customers table, sorted by City. Then, in the datagrid's click event, I
throw the following into a messagebox:
DataGrid1.CurrentCell.RowNumber
In each case, the row returned is the actual physical row of the datagrid.
What results do you obtain? Please detail the specific steps you are using
in code to get incorrect results, as well as the version of the .Net
Framework you are using.
(Note that this rowNumber is zero-based, so the first row is 0).
Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies
This posting is provided "AS IS" with no warranties, and confers no rights.
Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026? If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03- 026.asp and/or to
visit Windows Update at
http://windowsupdate.microsoft.com to install the