Reputation: 37
I am quite new and really struggle with the below issue:
I have a below column, which loads data correctly:
<xcdg:Column Title="TestData" FieldName="TestData" Width="1*" >
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.
Upvotes: 0
Views: 75
Reputation: 319
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;
}
Upvotes: 1