Hi,
I am having issues getting the correct SelectedRows when in GroupBy mode. What is the proper to do this. When I click on the GroupRows i am getting that Row added to the SelectedRows connection.
Here is the code I have in the grid's MouseDown event:
//get the row the cursor is on
int row = this.c1TrueDBGrid1.RowContaining(e.Y);
if (row != -1)
{
// if the row is in the SelectedRows collection then remove it (deselect)
// if it isn't then add it (select)
int index = this.c1TrueDBGrid1.SelectedRows.IndexOf(row);
if ((c1TrueDBGrid1.Splits[0].Rows[row].RowType == RowTypeEnum.DataRow))
{
if (index != -1)
this.c1TrueDBGrid1.SelectedRows.RemoveAt(index);
else
this.c1TrueDBGrid1.SelectedRows.Add(row);
}
StringBuilder sb = new StringBuilder();
foreach (int r in this.c1TrueDBGrid1.SelectedRows)
{
if (sb.Length != 0)
sb.Append(", ");
sb.Append(this.c1TrueDBGrid1.Columns[0].CellValue(r));
}
textBox1.Text = sb.ToString();
}
I have the following statement in the SelChange event
e.Cancel =
true;
Here is the code I am using to create a test DataTable to use for the grid.
private DataTable GetTestGroupingData()
{
DataTable dt = new DataTable();
dt.Columns.Add(
new DataColumn("ID", System.Type.GetType("System.Int32")));dt.Columns.Add(new DataColumn("Description", System.Type.GetType("System.String")));
dt.Columns.Add(
new DataColumn("AnalysisName", System.Type.GetType("System.String")));dt.Columns.Add(new DataColumn("Comment", System.Type.GetType("System.String")));
dt.Columns.Add(
new DataColumn("StartDate", System.Type.GetType("System.DateTime")));object[] rowVals = new object[5] {1, "Metals Run #1", "Run_1", "Choked", System.DateTime.Today };
dt.Rows.Add(rowVals);
object[] rowVals2 = new object[5] { 2, "Metals Run #1", "Run_2", "Non-Choked", System.DateTime.Today };
dt.Rows.Add(rowVals2);
object[] rowVals3 = new object[5] { 3, "Metals Run #2", "Run_1", "Non-Choked", System.DateTime.Today };
dt.Rows.Add(rowVals3);
object[] rowVals4 = new object[5] { 4, "Metals Run #3", "Run_1", "Choked", System.DateTime.Today };
dt.Rows.Add(rowVals4);
object[] rowVals5 = new object[5] { 5, "Metals Run #3", "Run_2", "Choked", System.DateTime.Today };
dt.Rows.Add(rowVals5);
object[] rowVals6 = new object[5] { 6, "Metals Run #3", "Run_3", "Non-Choked", System.DateTime.Today };
dt.Rows.Add(rowVals6);
return dt;
}
When in GroupBy mode I want to get the correct rows added to the SelectedRows Collection when clicking on DataRows. I also want to have the correct rows selected when I switch back and forth between have no rows grouped by and having rows grouped by.
Does anybody have any thoughts?