3

I am trying to create a databound WPF GridView whose rows can either be read-only or editable (by double-clicking or through a context menu). I would like for the row to return to a read-only state if any of its editable controls loses focus. The functionality I am looking for is very similar to this example but with an entire row being editted simultaneously (rather than a single cell). Does anyone know how to implement this?

4 Answers 4

7

there is also the "official" wpf datagrid from microsoft at codeplex : http://www.codeplex.com/wpf

3

With the ListView + GridView control il quite complex because this control "thinks in column" so you have to create a template for every column and switch the read-only template with edit template (for every cell). I suggest you to take a look a the xceed DataGrid. It's free and it implements the edit functionality in a simpler way (you can find info here: http://xceed.com/Grid_WPF_Intro.html)

2
  • 3
    800 dollars doesn't look free to me. Dec 17, 2009 at 22:03
  • 5
    The post is quite old. Now xceed don't offer the grid for free anymore. Last year there was a free edition. Now you could use the WpfToolkit (wpf.codeplex.com) that include a DataGrid.
    – ema
    Dec 18, 2009 at 7:42
2

The latest WPF has its own DataGrid. http://wpftutorial.net/DataGrid.html

0

This is an old question with an old answer, that this answer no longer works! In .Net 6, for editing Grid-View in WPF, you must use the "CurrentCellChanged" event.

UI:

<DataGrid x:Name="dataGrid" Margin="0,50,0,0" CurrentCellChanged="dataGrid_CurrentCellChanged"/>

Code:

public MainWindow()
{
    InitializeComponent();

    List<myDataType>? tmp;
    //Add data
    dataGrid.ItemsSource = tmp;
}

private void dataGrid_CurrentCellChanged(object sender, EventArgs e)
{
    myDataType tmp = (sender as DataGrid).SelectedItem as myDataType ;
    if (tmp != null)
    {
       //Do your job here
       //tmp has edited data
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.