How to get value of cell of particular row from gridgrouping control
Hi Rasika,
Thank you for your interest in Syncfusion products.
|
Query How to get cell
value from selected row? |
Method-1: If
you want to get the value of cell from selected row while using Allow Selection property, you can use
TableControlCellClick event. You can get cell value of selected row using
GetSelectedRows method and element class. Please make use of below code and attached
sample, this.gridGroupingControl1.TableOptions.AllowSelection
= GridSelectionFlags.Row; void
gridGroupingControl1_TableControlCellClick(object
sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgs
e)
{ if
(this.gridGroupingControl1.TableModel[e.Inner.RowIndex,
e.Inner.ColIndex].CellType == "RowHeaderCell")
//To check whether it is RowHeader { var
s = this.gridGroupingControl1.Table.SelectedRecords; GridRangeInfoList
s1 = this.gridGroupingControl1.TableModel.Selections.GetSelectedRows(true, true);//to get
row index range foreach
(GridRangeInfo info in s1) { Element
el = this.gridGroupingControl1.TableModel.GetDisplayElementAt(info.Top); string
cellValue = el.GetRecord().GetValue("SupplierID").ToString();//to
get cellvalue of particular column from selected row. } }
} |
|
Method-2
If
you want to get the value of cell from selected row while using ListBoxSelectionMode property, you can use SelectedRecordsChanging event. this.gridGroupingControl1.TableOptions.ListBoxSelectionMode
= SelectionMode.MultiExtended; void
gridGroupingControl1_SelectedRecordsChanging(object
sender, Syncfusion.Grouping.SelectedRecordsChangedEventArgs
e)
{ GridRangeInfoList
s1= this.gridGroupingControl1.TableModel.Selections.GetSelectedRows(true, true); foreach
(GridRangeInfo info in s1) { Element
el = this.gridGroupingControl1.TableModel.GetDisplayElementAt(info.Top); string
str = el.GetRecord().GetValue("SupplierID").ToString();
}
}
|
Please let me know if you have any concerns.
Regards,
Neelakandan
Attachment: Getting_Started_Demo_36ad39a1.zip
private void button1_Click(object sender, EventArgs e)
{
this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row;
GridRangeInfoList s1 = this.gridGroupingControl1.TableModel.Selections.GetSelectedRows(true, true);
foreach (GridRangeInfo info in s1)
{
Element el = this.gridGroupingControl1.TableModel.GetDisplayElementAt(info.Top);
string cellValue = el.GetRecord().GetValue("SupplierID").ToString();
MessageBox.Show("" + cellValue);
}
}
question:
why not show the following selected values: 9,10,11
Attachment: test003_319e916b.zip
Thanks for the update.
The GridRangeInfoList is the collection of individual ranges in the grid. To retrieve the rows from the GridRangeInfoList, we need to loop through the inner elements of GridRangeInfo which is retrieved from the GridRangeInfoList. Since, the Grid have the multiple selection ranges. Each range contains information about the selected rows separately. Please refer to the below code example,
Code Snippet:
private void button1_Click(object sender, EventArgs e)
{
this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row | GridSelectionFlags.AlphaBlend;
GridRangeInfoList s1 = this.gridGroupingControl1.TableModel.Selections.GetSelectedRows(true, true);
foreach (GridRangeInfo info in s1)
{
string cellValue = "";
//loop through the internal GridRangeInfo
for (int i = info.Top; i <= info.Bottom; i++)
{
Element el = this.gridGroupingControl1.TableModel.GetDisplayElementAt(i);
cellValue += "SupplierID = "+ el.GetRecord().GetValue("SupplierID").ToString() +"\n";
}
MessageBox.Show("" + cellValue);
}
}
Sample:
http://www.syncfusion.com/downloads/support/forum/117537/ze/Getting_Started_Demo1206885293
Regards,
Adhi.
- 3 Replies
- 4 Participants
-
RA Rasika
- Nov 5, 2014 11:57 AM UTC
- Sep 4, 2015 09:05 AM UTC