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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I disable a specific row and prevent clicking in Data Grid based on some condition?

Thread ID:

Created:

Updated:

Platform:

Replies:

149126 Nov 15,2019 07:15 AM UTC Nov 19,2019 05:03 PM UTC Xamarin.Forms 3
loading
Tags: SfDataGrid
asolute dev
Asked On November 18, 2019 08:51 AM UTC

I have created a data grid, there are total of three columns, firstName, lastName and age. I want to disable the specific row when the age value is less than 18. How can I achieve that? I have done some research online https://help.syncfusion.com/cr/xamarin/Syncfusion.SfDataGrid.XForms.SfDataGrid.html and I have created a method as following:

 private void DataGrid_DisableSpecifcRow(object sender, CurrentCellActivatingEventArgs e)
        {
            
        }

However, there is no example provided from that link. I am sure I need to add the event into my XAML file first but I don't know what event to be added and following is what I have so far.
<datagrid:SfDataGrid x:Name="dataGrid" Padding="0,20" GridTapped="Handle_GridTapped" HorizontalOptions="CenterAndExpand" AutoGenerateColumns="false" SelectionMode="Single" BackgroundColor="Transparent" QueryRowStyle="DataGrid_QueryRowStyle">
        datagrid:SfDataGrid>

I just don't know how to disable the specific row. Using the e, there is no option like e.RowIndex.Disable(). Thanks in advance.

Karthikraja Kalaimani [Syncfusion]
Replied On November 18, 2019 12:11 PM UTC

Hi asolute dev,

Thanks for contacting Syncfusion support.

Your requirement can be achieved by setting e.Cancel as true on CurrentCellActivating event. We have prepared a sample for the same.

Please follow the below code example,

 
dataGrid.CurrentCellActivating += DataGrid_CurrentCellActivating;

private
void DataGrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
{ 
    if (e.CurrentRowColumnIndex.RowIndex == 1) 
    { 
       e.Cancel = true; 
    } 
 } 

We hope this helps, please let us know if need further assistance from us.

Regards, 
Karthik Raja 


asolute dev
Replied On November 19, 2019 01:57 AM UTC

Hi Karthik Raja ,

Seems like the currentCellActivatingEvent is triggered after I click on the row and cause conflict between this event with the grid_tapped event. Even though the e.Cancel = true execute first, it still go to the grip_tapped event eventually. Is there any way to solve this kind of conflict?

Karthikraja Kalaimani [Syncfusion]
Replied On November 19, 2019 05:03 PM UTC

Hi asolute dev,

Thanks for the update.

Based on underlying data your requirement can be achieved. We have prepared sample for the same. 
For non-grouping cases please follow the below code example, 
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    if ((e.RowData as OrderInfo).Gender != "Female") 
    { 
        // here you can write business logic 
    } 
}

 
private void DataGrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
{ 
        int rowIndex = this.dataGrid.ResolveToRecordIndex(e.CurrentRowColumnIndex.RowIndex); 
…… 
else 
            { 
                //for non grouping cases 
                var record = this.dataGrid.View.Records[rowIndex]; 
                if ((record.Data as OrderInfo).Gender == "Female") 
                { 
                    e.Cancel = true; 
                } 
            }
…..
  
For grouping cases please follow the below code example,

 
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e) 
{ 
    if ((e.RowData as OrderInfo).Gender != "Female") 
    { 
        // here you can write bussiness logic 
    } 
}

private void DataGrid_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
{ 
        int rowIndex = this.dataGrid.ResolveToRecordIndex(e.CurrentRowColumnIndex.RowIndex); 
if (dataGrid.GroupColumnDescriptions.Count > 0) 
            { 
                // For grouping cases  
                var record = this.dataGrid.View.TopLevelGroup.DisplayElements[rowIndex]; 
                if (record is RecordEntry) 
                { 
                    var recordEntry = record as RecordEntry; 
                    var data = recordEntry.Data; 
                    if ((data as OrderInfo).Gender == "Female") 
                    { 
                        e.Cancel = true; 
                    } 
 
                } 
            }

}
 



Please let us know, if need further assistance from us.

Regards, 
Karthik Raja 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon