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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

What is the best way to access RowData in OnCurrentCellBeginEdit event with group columns

Thread ID:

Created:

Updated:

Platform:

Replies:

119619 Jul 15,2015 01:19 PM UTC Jul 18,2015 02:52 PM UTC WinRT 3
loading
Tags: SfDataGrid
Vasanth
Asked On July 15, 2015 01:19 PM UTC

Hi, 
I have a data grid with Group columns. I am using OnCurrentCellBeginEdit event to restrict write access to some cells based underneath row data values. Here is the code I am using inside OnCurrentCellBeginEdit  event:

if (args.Column.MappingName.Equals("Name"))
{
   var rowIndex = MyGrid.ResolveToRecordIndex(args.RowColumnIndex.RowIndex);
   var rowData = (MyGrid.View.Records[rowIndex]).Data as Student

   if (rowData.Discontinued)
      args.Cancel = true;
}

Problem is rowData returned is not the row inwhich I clicked on Name cell, I am guessing its because of the grouping row. What is the best way to correctly access RowData in OnCurrentCellBeginEdit   event. Please let me know.

Note: Both args.RowColumnIndex.RowIndex & MyGrid.ResolveToRecordIndex(args.RowColumnIndex.RowIndex) doesnt work well.



Jai Ganesh S [Syncfusion]
Replied On July 16, 2015 12:27 PM UTC

Hi Vasanth,


Thank you for using Syncfusion products.


We have analyzed your query. You can achieve your requirement like getting the row data from DisplayElements in grouping case by using the corresponding resolved record index.


Code Snippet [C#]:


void datagrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args)

        {

            if (args.Column.MappingName.Equals("EmployeeName"))

            {

                   var recordIndex = datagrid.ResolveToRecordIndex(args.RowColumnIndex.RowIndex);


                   if (this.datagrid.View.TopLevelGroup != null)

                   {

                       // Get the current row record while grouping

                       var record = this.datagrid.View.TopLevelGroup.DisplayElements[recordIndex];

                       // data of record as type cast to OrderInfo

                       var rowData = (record as RecordEntry).Data as BusinessObjects;

                       if (rowData.EmployeeName == "Mart")

                           args.Cancel = true;

                   }

                   else

                   {

                       // Get the current row record

                       var record1 = this.datagrid.View.Records.GetItemAt(recordIndex);


                       if ((record1 as BusinessObjects).EmployeeName == "Mart")

                           args.Cancel = true;

                   }

             }

        }



We have also prepared the sample based on this and please find the sample under the following location,


Sample: http://www.syncfusion.com/downloads/support/directtrac/141139/ze/SfDataGridDemo227932121


KB Link:

http://www.syncfusion.com/kb/2446/how-to-get-the-current-cell-value-when-you-click-the-cell


Please let us know if you need further assistance.


Thank you,

Jai Ganesh S


Vasanth
Replied On July 16, 2015 01:55 PM UTC

perfect, works like a champ. thank you!

Antony Raj M [Syncfusion]
Replied On July 18, 2015 02:52 PM UTC

Hi Vasanth,


Thanks for your update. Please let us know if you need further assistance on this.


Regards,
Antony Raj

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.

Warning Icon 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.Close Icon

;