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

GridGgroupingControl and GridDataBoundGrid - get DataBound Object from Row

I want to get DataBound object from row from GridGgroupingControl and GridDataBoundGrid when I make double click on grid.

For example, I have List<User> DataSource bound to grid. User is class which has UserName, Name, Surname and E-mail properties.
So in grid_double_click event I want to get:
1. object/s from selected Row/s, something like var userObject = grid.DataBoundItemFromRow... 
2. value from ID column, something like int ID = grid[row, "ID"] ...

How to achieve this with GridGgroupingControl and GridDataBoundGrid. Can you please make an example.

Thank You,

Regards

6 Replies

SA Solai A L Syncfusion Team December 11, 2015 06:34 AM UTC

Hi Customer,

Thank you for using Syncfusion products.

To get record values in double click event of Grid Grouping Control
Please find the below code example and sample to get the doublecliked cell’s record.

Code Example :

this.gridGroupingControl1.TableControlCellDoubleClick += new GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCellDoubleClick);

       

void gridGroupingControl1_TableControlCellDoubleClick(object sender, GridTableControlCellClickEventArgs e)

        {

            Record rec = this.gridGroupingControl1.Table.CurrentRecord;

            string column1value = rec.GetValue("Id").ToString();

            string column2value = rec.GetValue("A").ToString();

            string column3value = rec.GetValue("B").ToString();

            string column4value = rec.GetValue("Date").ToString();

            string column5value = rec.GetValue("Value").ToString();


        }

Sample :

http://www.syncfusion.com/downloads/support/forum/121399/ze/WindowsFormsApplication_recordvalue984172926


Note : We have used cell doubleclick event, you can use any other double click event to as per your need with the same code.

To get record values in double click event of grid data bound grid
Please find the below code example and sample to get the doublecliked cell’s record.

Code Example :

   this.gridDataBoundGrid1.CellDoubleClick += new GridCellClickEventHandler(gridDataBoundGrid1_CellDoubleClick);

   this.gridDataBoundGrid1.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(gridDataBoundGrid1_PrepareViewStyleInfo);          

    

void gridDataBoundGrid1_CellDoubleClick(object sender, GridCellClickEventArgs e)

        {

            isdoubleclick = !isdoubleclick;

        }

void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)

        {


            if (isdoubleclick && e.RowIndex > 0 && e.ColIndex > 0)

            {

                CurrencyManager cm = (CurrencyManager)BindingContext[gridDataBoundGrid1.DataSource, gridDataBoundGrid1.DataMember];


                DataRow row;


                DataView dv = (DataView)cm.List;

                //The 2 is the rowindex.


                int position = this.gridDataBoundGrid1.Binder.RowIndexToPosition(e.RowIndex);


                row = dv[position].Row;

                object[] SelectedRow = row.ItemArray;

            }

          

        }


Sample :

http://www.syncfusion.com/downloads/support/forum/121399/ze/GDBG_recordvalue-746634142


Note : We have used cell DoubleClick event, you can use any other double click event to as per your need with the same code.




Thanks,
AL.Solai.




SY SysNop December 11, 2015 08:26 AM UTC

Thank You for explanation but, I need something like this which you can do with  DataGrid:

object objectInGrid = dataGridView1.SelectedRows[0].DataBoundItem;

In this way I can get whole databound object from selected row. 
How I can do that with GridDataBoundGrid and GridGroupingControl?

Thank You, 

Regards


SY SysNop December 11, 2015 12:26 PM UTC

I figured it out.

Thank You.

Regards.


SA Solai A L Syncfusion Team December 14, 2015 05:07 AM UTC

Hi Customer,

Thank you for your update.

We are glad to know that your issue has been resolved. Please let us know if you have any concerns in future.

Thanks,
AL.Solai.


AR Arnaud January 15, 2018 04:53 PM UTC

Another solution :   (DataBoundItem )

ClassObj myObj = this.gridGroupingControl1.Table.CurrentRecord.GetData() as ClassObj;


PM Piruthiviraj Malaimelraj Syncfusion Team January 16, 2018 08:34 AM UTC

Hi Ferderic, 

Thanks for your update. 

Yes, you are right. The binding source object can be get by using CurrentRecord of Table. 

Regards, 
Piruthiviraj 


Loader.
Up arrow icon