在datagridview WPF中更改单元格的值 [英] Change value of cell in datagridview WPF

查看:451
本文介绍了在datagridview WPF中更改单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everybody,

我正在编写程序使用wpf。在我使用winform之前,现在使用wpf。这很难。

我使用datagridview来显示数据库sql中的数据。但现在我想在单击按钮时更改datagridview中的1个单元格。

在winform中我写道:

Hello Everybody,
I am write a program use wpf. Before i used winform, now using wpf. this is vr difficult.
I am using datagridview to display data from database sql. But now i want to change 1 cell in datagridview when click a button.
In winform i wrote:

for (int i = 0; i < dtg_IP.Rows.Count - 1; i++)
           {
               if (dtg_IP.Rows[i].Cells[0].Value.ToString() == ip)
                   {
                       dtg_IP.Rows[i].Cells[4].Value = "Online";
                   }
               }
           }



在wpf,我试过但我不知道如何:((。你能帮助我吗?谢谢你这么多。



我期待你的解决方案。



我有什么尝试过:



我在WPF的datagridview中得到单元格的值:



foreach( Data.dowView Row_dtg in this.dtg_IP.Items)

{

if(Row_dtg.Row.ItemArray [0] .ToString()== ip)



{

//

}

}


in wpf, i tried but i dont know how :((. Can you help me? thank you so much.

I look forward a solution from you.

What I have tried:

I get value of cell in datagridview in WPF:

foreach (DataRowView Row_dtg in this.dtg_IP.Items)
{
if (Row_dtg.Row.ItemArray[0].ToString() == ip)

{
//
}
}

推荐答案

嗨。



我遇到了类似的问题。

我用按钮中的代码解决了这个问题:

Hi.

I had a similar problem.
I solved it with this code in the button:
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Path=DataContext.BrowseFolders}"                                                             CommandParameter="{Binding Name}"/>







这样我的数据网格改变了值单击按钮的行。



不知道是否有帮助



祝你好运:

Richard




This way my datagrid changed the value of the line where the button was clicked.

Don't know if it helps

Best regards:
Richard


这篇关于在datagridview WPF中更改单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆