BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
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
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() +"";
}
MessageBox.Show("" + cellValue);
}
}
Sample:
http://www.syncfusion.com/downloads/support/forum/117537/ze/Getting_Started_Demo1206885293
Regards,
Adhi.