Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to make some particular cells in grid as read only?

Sort Posts: Previous Next
  •  07-01-2010, 1:54 AM Post no. 27356

    How to make some particular cells in grid as read only?

    here is the code which i was trying to achieve to make some particular cells as read only.I used a converter class which i defined in the

    when i am using this code in my project it is setting the whole row to readonly...........

    public class OutturnReadOnlyConverter:IValueConverter

    {

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    if (value != null)

    {

    DataRow objDataRow = (DataRow)value;

    for (int i = 0; i < objDataRow.ItemArray.Length;i++)

    {

    string strValue = objDataRow.ItemArrayIdea.ToString();

    if (strValue == "-99")

    return true;

    }

     

    return false;

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    return null;

    throw new Exception("The method or operation is not implemented.");

    }

    #endregion

    }

     

    The XAML part where i am declaring the converter class is below in this format:

    <xcdg:DataGridControl.Resources>

    <local:OutturnReadOnlyConverter x:Key="OutturnReadOnly"/>

    <Style TargetType="{x:Type xcdg:DataCell}">

    <Setter Property="ReadOnly" Value="{Binding Converter={StaticResource OutturnReadOnly}}" />

    </Style>

    </xcdg:DataGridControl.Resources>

     

    Can anyone help me out regarding this issue?

  •  07-01-2010, 2:23 AM Post no. 27357 in reply to 27356

    Re: How to make some particular cells in grid as read only?

    Since your Style is set to target DataCell, it is being applied to all cells in your grid. In the converter, you are looping through all the DataRow values and returning true if any of them are -99. Therefore if any cell in a row is -99, the whole row will be set to ReadOnly - which is what you are seeing.

    Rather than pass the whole DataRow to your converter, you need to pass just the cell value.

  •  07-01-2010, 2:36 AM Post no. 27359 in reply to 27357

    Re: How to make some particular cells in grid as read only?

    how to pass the cell value to the converter?can please let me know, because the Value parameter fetches me the datarow,from the Value how to extract the cell ie..
  •  07-01-2010, 2:58 AM Post no. 27361 in reply to 27357

    Re: How to make some particular cells in grid as read only?

    Since my converter is derived from IValueConverter Class ,it only gets me the dataRow(Value) as the value,and is their anyway of passing cell value to the converter ?Can you please let me know if their is any other way of overcoming this problem
  •  07-01-2010, 4:13 AM Post no. 27362 in reply to 27361

    Re: How to make some particular cells in grid as read only?

    Not something I have done, but doing a search in forum has suggested (not tried it), that you change your Binding to the following:

    {Binding Path=.,RelativeSource={RelativeSource Self},Converter={StaticResource OutturnReadOnly}}

    This apparently gives you the value of the DataCell. 

     

  •  07-01-2010, 12:23 PM Post no. 27370 in reply to 27362

    Re: How to make some particular cells in grid as read only?

    Thanks for the reply Derek ,i  will get back to you once i check it in my application.
  •  07-02-2010, 8:58 AM Post no. 27383 in reply to 27370

    Re: How to make some particular cells in grid as read only?

    hi derek

    It is working it's fetching me the cell value and here is the code which works fine for making some particular cells as read only

    <xcdg:DataGridControl.Resources>

    <local:OutturnReadOnlyConverter x:Key="OutturnReadOnly"/>

    <Style TargetType="{x:Type xcdg:DataCell}">

    <Setter Property="ReadOnly" Value="{Binding Path=.,RelativeSource={RelativeSource Self},Converter={StaticResource OutturnReadOnly}}" />

    </Style>

    </xcdg:DataGridControl.Resources>

     

    and the front end  code looks like this

     

    public class OutturnReadOnlyConverter:IValueConverter

    {

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    DataCell objDataRow = (DataCell)value;

    if(objDataRow.HasContent)

    {

    if (objDataRow.Content.ToString() == "-99")

    return true;

     

    }

    return false;

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

    return null;

    throw new Exception("The method or operation is not implemented.");

    }

    #endregion

    }

    Filed under: ,
  •  09-20-2010, 2:05 AM Post no. 28750 in reply to 27383

    Re: How to make some particular cells in grid as read only?

    I used the code presented here, but I encountered 2 problems:

    1. The DataGrid doesn't fill all available width anymore, if I use

    <Style TargetType="{x:Type xcdg:TableViewScrollViewer}">
            <Setter Property="CanContentScroll" Value="False" />
    </Style> - to disable virtualization

    2. The ReadOnly cells doesn't keep their readonly attribute on scrolling.

    Any help is appreciated

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.