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 the Position of a Row in the DataSource from the Current Record

Dear Sir :

Good day , today I try to Get the Position of a Row in the DataSource from the Current Record, and your reference as below link 
http://help.syncfusion.com/ug/windows%20forms/index.html#!documents/howtogetthepositionofarowinthedatasourcefromthecurrentrecord.htm


Base on your sample , 

[C#]
 
Table table = e.TableControl.Table;
 
//Gets the current display element.
Element el = table.DisplayElements[e.rowIndex];
 
//Gets the current record.
Record r = el.ParentRecord;
 
//Finds its row position.
int dataRowPos = table.UnsortedRecords.IndexOf(r);
 
//Retrieves the corresponding data row from the datasource.
CustomersDataRow row = dataSoure.Rows[dataRowPos];
 
// Accesses the CutomerId value of the current record.
string id = row.CustomerId;

I would like to know what is the "e.rowIndex", as the select row index value may not complete event function

Thank you

Michael


1 Reply

MA Mahendran Annamalai Syncfusion Team August 10, 2015 01:49 PM UTC

Hi Michael,

Thanks for using syncfusion products.

We have analyzed your query. In the mentioned code e.rowindex having value of CurrentCell located Rows index value. We have prepared work around sample by using TableControlCellClick event. We will update the same code snippet to mentioned  UGlink Please refer below code snippet.

void gridGroupingControl1_TableControlCellClick(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgs e)

{

    try

    {

        Table table = e.TableControl.Table;


        // Gets the current display element.

        Element el = table.DisplayElements[e.Inner.RowIndex];


        // Gets the current record.

        Record r = el.ParentRecord;

               

        //Finds its row position.

        int dataRowPos = table.UnsortedRecords.IndexOf(r);


        //Retrieves the corresponding data row from the datasource.

        DataRow dr = dt.Rows[dataRowPos];

               

        //Accesses the CutomerId value of the current record.or 1198

        this.textBox1.Text = dr["CustomerId"].ToString();


    }

    catch { }

}


And also we have attached workaround sample for this. Please find sample from below location.

Sample: GetRowPositionGC-CS


For more information, please refer KBLink.

Please let us know If you have any queries.

Thanks,
Mahendran.A

Loader.
Up arrow icon