This is a migrated thread and some comments may be shown as answers.

Disable and clear certain cell

5 Answers 560 Views
GridView
This is a migrated thread and some comments may be shown as answers.
heavywoody
Top achievements
Rank 1
heavywoody asked on 25 Jan 2018, 12:35 AM

I want to always disable and, if I can, clear the content of the first cell in the first row of my RadGridView.  I know there is the readonly property to use, but that doesn't really work because then my objects need that field to bind to.  It is static for me that in the first row, the first cell is always disabled.  So no matter how the user moves around the rows or data, that cell remains static.

How can I do this?

5 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 29 Jan 2018, 01:36 PM
Hello Christian,

You can achieve your requirement by setting the IsEnabled property of the GridViewCell to false. You can do that via the CellStyle property of the gridview column. You can see this approach shown in the attached project. I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
heavywoody
Top achievements
Rank 1
answered on 30 Jan 2018, 03:57 PM

Thanks for the example WPF project.  I see how you are disabling the cell by criteria.  I am still missing one piece of this.  Within the converter you have, how do I check if the cell is the first cell in the grid?  In pseudo code something like:

if(cell.row==0&&cell.column=0)

disable

else

don't disable it

If it helps, the reason I am doing this is I am creating a query builder.  I don't want the And/Or dropdown column to appear in the first row of the grid because it wouldn't make sense.  However, if a user re-ordered the rows, it would mean a different row could become the first row, which should immediate set the value of the cell to blank and disable it.  So that is where I have been struggling is how do you identify in index of the cell in order to set it to read only?  Could you tell me how or adjust the project to show me so the first cell in the grid is always blanked and disabled regardless of the data in it?

0
heavywoody
Top achievements
Rank 1
answered on 30 Jan 2018, 04:19 PM
Essentially, I am trying to get a solution that doesn't depend on underlining data for evaluation.  If it is cell(0,0), it is always disabled.
0
heavywoody
Top achievements
Rank 1
answered on 30 Jan 2018, 08:56 PM
So ideally, if I could put gridMain.Cells[0,0].IsEnabled=false, that is what I would like to do.  It has nothing to do with underline data. I don't need virtualization on if that affects it.  But I can't figure out how to do this.
0
Martin Ivanov
Telerik team
answered on 02 Feb 2018, 03:07 PM
Hello Christian,

In my project I used the Id property to indicate if the cell is empty. You can try to implement this also on your side. For example, you can add a bool property that tells if the record is placed in the first row of the first column. 

To get the cell's row and column without involving the view model, you can use the Items and Columns collections of the gridview. Here is an example in code:
public class GridViewCellToBoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {  
        var cell = value as GridViewCell;
        if (cell != null)
        {
            var data = (RowInfo)cell.DataContext;
            var gridView = cell.DataColumn.DataControl;
            var rowIndex = gridView.Items.IndexOf(data);
            var columnIndex = cell.DataColumn.DisplayIndex;
            if (rowIndex == 0 && columnIndex == 0)
            {
                return false;
            }
            return true;
        }
        return false;
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
heavywoody
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
heavywoody
Top achievements
Rank 1
Share this question
or