Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在wpf中更新datagrid中特定行的specfic列_C#_Wpf_Datagrid - Fatal编程技术网

C# 在wpf中更新datagrid中特定行的specfic列

C# 在wpf中更新datagrid中特定行的specfic列,c#,wpf,datagrid,C#,Wpf,Datagrid,我在WPF中有一个数据网格(IDdgShowSearching),在同一个数据网格中包含一个按钮 点击按钮,我做一些操作 执行操作后,我想更新同一行中的两列 列名是Status和AddedRecords 列索引为6和5 如何做到这一点 下面是点击按钮的代码 private void Update_Click(object sender, RoutedEventArgs e) { DataGrid grvRow = FindVisualParent<DataGrid>(sender

我在WPF中有一个数据网格(ID
dgShowSearching
),在同一个数据网格中包含一个按钮

点击按钮,我做一些操作

执行操作后,我想更新同一行中的两列

列名是
Status
AddedRecords

列索引为
6
5

如何做到这一点

下面是点击按钮的代码

private void Update_Click(object sender, RoutedEventArgs e)
{
 DataGrid grvRow = FindVisualParent<DataGrid>(sender as UIElement);
 if (grvRow != null)
 {
     // SOME OPERATIONS PERFORMED
     // ................ 

     // Here I want to update two columns in the same row ??
     // DataGrid id is dgShowSearching 

 }
}

 public static T FindVisualParent<T>(UIElement element) where T : UIElement
        {
            UIElement parent = element;
            while (parent != null)
            {
                T correctlyTyped = parent as T;
                if (correctlyTyped != null)
                {
                    return correctlyTyped;
                }
                parent = VisualTreeHelper.GetParent(parent) as UIElement;
            }
            return null;
        }
private void Update\u单击(对象发送方,路由目标)
{
DataGrid grvRow=FindVisualParent(发送方作为UIElement);
如果(grvRow!=null)
{
//进行了一些手术
// ................ 
//这里我想更新同一行中的两列??
//正在搜索数据网格id
}
}
公共静态T FindVisualParent(UIElement元素),其中T:UIElement
{
UIElement父元素=元素;
while(父级!=null)
{
T correctlyTyped=父项为T;
if(correctlyTyped!=null)
{
返回正确类型;
}
parent=VisualTreeHelper.GetParent(parent)作为UIElement;
}
返回null;
}

try
FindVisualParent
dgShowSearching.SelectedItem as DataGridRow
我需要在一些后台工作进程之后更新列您可以使用
RunWorkerAsync(Object)
方法将行作为状态传递给后台工作进程,完成修改后,使用前面传递的DataGridRow实例的
RunWorkerCompletedEventArgs.UserState
属性执行修改