Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Having XamGrid Cells read only
posted

Hi there,

I am created an application using MVVC and currently using a XamGrid to display email configurations. I want one of the columns in the results to be readonly and not editable. I tried adding the ReadOnly=True on the XAML, but since I have a Add New Row setting aswell, setting this to true, doesnt allow me to input anything in this row when creating a new row. Is there a way to set the readonly property on the results without affecting the ReadOnly column?

Thanks in advance,

Julio

Parents
  • 2406
    Verified Answer
    posted

    Hi Julio,

    If I properly understand your question, you need to be able to change a column cell value when adding a row and not changing it in on Editing. This could be achieved using a TemplateColumn with a TextBox as an EditorTemplate and change its IsReadOnly property value starting editing depending on what is started – editing or adding. Here is a sample code snippet:

    <ig:XamGrid x:Name="Grid1" CellEnteredEditMode="Grid1_CellEnteredEditMode" CellExitingEditMode="Grid1_CellExitingEditMode" …………..…>

    ……………………….

    <ig:TemplateColumn Key="PropertyName">

        <ig:TemplateColumn.ItemTemplate>

            <DataTemplate>

                <TextBlock Text="{Binding PropertyName}" />

            </DataTemplate>

        </ig:TemplateColumn.ItemTemplate>

        <ig:TemplateColumn.EditorTemplate>

            <DataTemplate>

                <TextBox x:Name="NameEditorTemplateTextBox" Text="{Binding PropertyName}" IsReadOnly="True" />

            </DataTemplate>

        </ig:TemplateColumn.EditorTemplate>

    </ig:TemplateColumn>

     

    private void Grid1_CellExitingEditMode(object sender, ExitEditingCellEventArgs e)

    {

        if (e.Cell.Column.Key == "Name" && !e.EditingCanceled && e.Cell is AddNewRowCell)

        {

            TextBox tb = e.Editor as TextBox;

            tb.IsReadOnly = true;

        }

    }

     

    private void Grid1_CellEnteredEditMode(object sender, EditingCellEventArgs e)

    {

        if (e.Cell.Column.Key == "Name" && e.Cell is AddNewRowCell)

        {

            TextBox tb = e.Editor as TextBox;

            tb.IsReadOnly = false;

        }

    }

     

    Let me know if this helps.

     

    Thank you!

    Petia

     

Reply Children
No Data