0

I am quite new and really struggle with the below issue:

  1. I have a below column, which loads data correctly:

                 <xcdg:Column Title="TestData" FieldName="TestData" Width="1*" >
    
  2. But I would need to modify it, by selecting a value from a popup window.

    I already solved similar before, but it was for textbox:

                            <TextBox  Grid.Row="1" Grid.Column="1" Text="{Binding Model.TestData}">
                                <TextBox.InputBindings>
                                    <KeyBinding Key="F12" Command="{Binding SearchCommand}" CommandParameter="TestData"></KeyBinding>
                                </TextBox.InputBindings>
                            </TextBox>
    

Not sure if more information needed about the popup, basically it gives back the selected value, which should get to the column.

Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Denis
  • 37
  • 1
  • 6

1 Answers1

1

You can simply assign the new value to the appropriate cell.

DataRowView drv = myDataGrid.CurrentItem as DataRowView;
drv["FieldName"] = "New Value";

In the example shown below, I use a popup window with properties for ID, Name and Result. It will display the ID and Name provided. The user can edit the Name (I made the ID field read only), and then click either the OK or Cancel button. Both will close the popup, but only clicking the OK button will set the Result property to true before closing. I can then check this Result property to know if I should update the cell in my grid.

private void btnShowPopup_Click(object sender, RoutedEventArgs e)
{
    // Get the grid's current row
    DataRowView drv = this.myGrid.CurrentItem as DataRowView;

    // Popup shows product's ID and Name (user can only edit Name)
    Popup popup = new Popup();
    popup.ProductID = drv["ProductID"].ToString();
    popup.ProductName = drv["ProductName"].ToString();
    popup.ShowDialog();

    // Apply changes if user clicked the OK button
    if (popup.Result == true)
        drv["ProductName"] = popup.ProductName;
}
Diane-Xceed
  • 319
  • 1
  • 6
  • Thanks for your time sharing this! Could you also share the xaml, please? I am wondering what triggers the popup to show-up in this case? (for now I had to change to regular DataGrid with CustomCellTemplate to make it work, but would be cool to learn how to do it in xceed) – Denis Aug 05 '16 at 14:54
  • I didn't do anything fancy as I was just doing a quick test, so I just added a button under the DataGrid and manually clicked it. If you want the popup to appear in reaction to a user action on the DataGrid, you would have to capture that event and call the popup from there. If you have a specific scenario in mind and need help, I recommend contacting us by email: support@xceed.com – Diane-Xceed Aug 05 '16 at 18:21