We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to get value of cell of particular row from gridgrouping control

Hi,
I am using gridgrouping control.
I want to fetch the value of cell of selected row from gridgrouping control.
Is any method for this?
Please give me any solution regarding to this issue.
 
Regards,
Rasika

3 Replies

NK Neelakandan Kannan Syncfusion Team November 7, 2014 05:24 AM UTC

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


GP Gregory Pe September 3, 2015 12:22 PM UTC

Hi,
I added
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


Regards,
Grzegorz



Attachment: test003_319e916b.zip


AK Adhikesevan Kothandaraman Syncfusion Team September 4, 2015 09:05 AM UTC

Hi Grzegorz,

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() +"";                  

        }               

        MessageBox.Show("" + cellValue);

    }
}

Sample:
http://www.syncfusion.com/downloads/support/forum/117537/ze/Getting_Started_Demo1206885293

Regards,
Adhi.


Loader.
Live Chat Icon For mobile
Up arrow icon