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

Edit datagrid cell based on condition

Sort Posts: Previous Next
  •  06-29-2011, 11:51 AM Post no. 30663

    Edit datagrid cell based on condition

    Hi Guys,

    I am using 3.7 wpf datagrid control. 

    I have a bound datagrid control with four columns. First column is checkbox, 2nd is read only and 3rd & 4th are editable columns with textbox editor.

    Now I want user to allow cell of 3rd & 4th columns only if checkbox is checked in first column. 

    I don't want to user to start editing values in 3rd and 4th columns without selecting checkbox field.

    Any idea? how can I achieve this? 

    i tried implementing checkbox template and handling checkbox checked event as folllow:

     private void CheckBox_Checked(object sender, RoutedEventArgs e)

    {

             DataRow dr = mygrid.GetContainerFromItem(mygrid.CurrentItem) as DataRow;

             if (dr != null)

    {

    Cell cel = dr.Cells[2];

    if (cel != null)

    {

    cel.ReadOnly = false;

    cel.BeginEdit();

    }

    }

    }

     but I am getting below error as I kept columns read only

    "An attempt was made to edit a read-only cell or the cell content is not bound using two way binding."

    Thanks

     

     

     

     

     

     

     

    Filed under:
  •  06-30-2011, 10:05 AM Post no. 30670 in reply to 30663

    Re: Edit datagrid cell based on condition

    Guys,

    Any suggestion on problem listed above? 

     

  •  07-04-2011, 11:17 PM Post no. 30680 in reply to 30670

    Re: Edit datagrid cell based on condition

    Attachment: TableFlowSample.zip
    Hi Hiren, This can be achieved by handling the PreviewMouseDown event on DataCell and checking if the current cell satisfies the needed conditions to be editable, if it is not, you can set e.handled to false on that cell which would disable the cell from going into edit mode. I attached a small sample that demonstrates how to achieve this.
    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  07-08-2011, 11:46 AM Post no. 30694 in reply to 30680

    Re: Edit datagrid cell based on condition

    Thanks Michel, it worked for me.

    Cheers,

    Hiren Jani 

     

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