Populate a Grid Control when a row is selected on another Grid Control
Hi,
I have two Grid Controls. I want to know how to populate the second grid control when a row a selected on first grid control. When the row selected is changed the second grid control deletes the previous entries and populates with a new set of values.
I am triggering the event of selection by using
this.gridControl.CurrentCellActivating += this.GridControlOnCurrentCellActivating;
Is it possible to provide a working example for reference?
SIGN IN To post a reply.
3 Replies
MG
Mohanraj Gunasekaran
Syncfusion Team
July 17, 2017 11:34 AM UTC
Hi JeeNew,
Thanks for using Syncfusion product.
|
Query |
Solution |
|
I have two Grid Controls. I want to know how to populate the second grid control when a row a selected on first grid control. When the row selected is changed the second grid control deletes the previous entries and populates with a new set of values. |
Suggestion 1
In order to update the selected value in second grid, you can use the PopulateValues method in SelectionChanged event. Please refer to the below code example,
Code example
this.gridControl1.SelectionChanged += gridControl1_SelectionChanged;
void gridControl1_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
this.gridControl2.ColCount = this.gridControl1.ColCount;
this.gridControl2.RowCount = e.Range.Height;
DataTable table = new DataTable();
foreach(DataColumn column in dt.Columns)
{
table.Columns.Add(column.ColumnName);
}
for (int j = 0; j < e.Range.Height; j++)
{
DataRow dr = table.NewRow();
for (int i = 0; i < this.gridControl1.ColCount; i++)
{
dr[i] = this.gridControl1[e.Range.Top + j, i+1].CellValue;
}
table.Rows.Add(dr);
}
this.gridControl2.PopulateValues(GridRangeInfo.Cells(1, 1, this.gridControl2.RowCount, this.gridControl2.ColCount),table);
this.gridControl2.Refresh();
} |
|
Suggestion 2
Also, you can achieve your scenario by setting the value for cells directly in SelectionChanged event. Please refer to the below code,
Code example
void gridControl1_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
this.gridControl2.ColCount = this.gridControl1.ColCount;
this.gridControl2.RowCount = e.Range.Height;
this.gridControl2.PopulateHeaders(GridRangeInfo.Cells(0, 1, gridControl2.RowCount, gridControl2.ColCount), dt);
for (int j = 0; j < e.Range.Height; j++)
{
for (int i = 0; i < this.gridControl1.ColCount; i++)
{
this.gridControl2[1 + j, i].CellValue = this.gridControl1[e.Range.Top + j, i].CellValue;
}
}
}
| |
|
Suggestion 3
By default, GridControl does not have the direct support to update the values automatically in second GridControl. If you want to update the changes in GridControl2 based on GridControl1, you can use the CurrentCellEditingComplete event. Please refer to the below code example,
Code example
|
Please let us know, if we misunderstood your scenario.
Regards,
Mohanraj G
JE
JeeNew
July 18, 2017 05:34 AM UTC
Hi Mohanraj,
Thanks, your suggestions worked well for me.
Thanks,
MG
Mohanraj Gunasekaran
Syncfusion Team
July 19, 2017 04:03 AM UTC
Hi JeeNew,
Thanks for your update.
We are glad to know that your reported problem has resolved.
Please let us know, if you have any concerns.
Regards,
Mohanraj G
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JE JeeNew
- Jul 14, 2017 05:54 AM UTC
- Jul 19, 2017 04:03 AM UTC