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.
Unfortunately, activation email could not send to your email. Please try again.

GridGgroupingControl and GridDataBoundGrid - get DataBound Object from Row

Thread ID:

Created:

Updated:

Platform:

Replies:

121399 Dec 10,2015 01:52 AM Jan 16,2018 03:34 AM Windows Forms 6
loading
Tags: GridDataBoundGrid(Classic)
SysNop
Asked On December 10, 2015 01:52 AM

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

Solai A L [Syncfusion]
Replied On December 11, 2015 01:34 AM

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.



SysNop
Replied On December 11, 2015 03:26 AM

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

SysNop
Replied On December 11, 2015 07:26 AM

I figured it out.

Thank You.

Regards.

Solai A L [Syncfusion]
Replied On December 14, 2015 12:07 AM

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.

BRIEF Frederic
Replied On January 15, 2018 11:53 AM

Another solution :   (DataBoundItem )

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

Piruthiviraj Malaimelraj [Syncfusion]
Replied On January 16, 2018 03:34 AM

Hi Ferderic, 

Thanks for your update. 

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

Regards, 
Piruthiviraj 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;