Hello,
my Problem is simple. I use a sfDatagrid that i bind to a BindingSource with an underlaying TableAdapter (ADO.NET to SqlServer; but only for selection!).
I fill the Grid and add an additional 'Checkbox-Column' in code.
Now i use an second select to look for the rows where i want to set the checkstate in Code.
As far as i read, i should use a Statement like this:
foreach (var record in sf_DataGrid.View.Records)
{
var Akt_Row = record.Data;
int iID = (int) ((System.Data.DataRowView)Akt_Row ).Row.ItemArray[0];
if (iID == ii)
{
((System.Data.DataRowView)Akt_Row ).Row.ItemArray[6] = 1; --Column with the Checkbox!
}
}
The Statement is running with no error, but also with no result!
What is my fault?
Should i use an other Grid?
Should i use an other DataSource since i only Need a simple int ID, string Name structure from the database with an additional Checkbox that i set in Code?
Thanks
Patric
Ok, i found one solution.
I add a new column to my datatable and bind this table to the datagrid as datasource.
Then instead of Looping over the 'records' of the grid i loop over the datatable and set the new value.
userTableAdapter1.Fill(this.message_SystemDataSet1.User); // Fill the table in the dataset
dtUser = this.message_SystemDataSet1.User; // Copy to my datatable
dtUser .Columns.Add("in_Gruppe", typeof(bool)); // Add a column of type bool
sf_DG_User.DataSource = dtUser ; // Bind to the datagrid
Set_Grid();
void Set_Grid()
{
for (int i = 0; i < iAnz_Ben; i++) // Array of user to check
{
int iAkt_ID = int.Parse(Ben_IDs[i].ToString()); // ID of the User
for (int j = 0; j < dtUser .Rows.Count; j++)
{
int iTest = (int)dtUser .Rows[j].ItemArray[0];
if (iTest == iAkt_ID)
{
var change_Row = dtUser .Rows[j];
change_Row.BeginEdit();
change_Row[8] = true;
change_Row.EndEdit();
change_Row.AcceptChanges();
}
}
}
dtUser .AcceptChanges();
The changes in the datatable are sent to the datagrid and all works well.
Any better solution??
Patric