gpt4 book ai didi

c# - 比较数据网格中同一行的两个单元格

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:01 25 4
gpt4 key购买 nike

使用 C# .NET 4.5、MS visual studio 2012、WPF。

你好,这段代码终于可以运行了,它基本上是通过行遍历 datgrid。

请注意,他可能会冒犯那里所有的 WPF 向导!

public IEnumerable<System.Windows.Controls.DataGridRow> GetDataGridRow(System.Windows.Controls.DataGrid grid)
{
var itemsource = grid.ItemsSource as System.Collections.IEnumerable;
paretogrid.UpdateLayout();
if (null == itemsource) yield return null;
foreach (var item in itemsource)
{
var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow; // null?
if (null != row) yield return row;
}
}

private void ShowArrows()
{
var rows = GetDataGridRow(paretogrid); // fetching null?

foreach (DataGridRow r in rows)
{
DataRowView rv = (DataRowView)r.Item;
}
}

如您所见,我遍历了这些行。现在我想要做的是将列索引 2 处的单元格值与每个“行”上的列索引 4 进行比较,然后,如果是真或假,则相应地更新第 5 列。我可以遍历列,这让我可以逐个单元格,但这不是我想要的,例如

foreach (DataGridColumn column in paretogrid.Columns)

是不是像这样:

paretogrid.Columns[2].GetCellContent(something here) as textblock;

最佳答案

请看下面的解释,这将有助于弄清楚为什么你会看到你所看到的

好的,让我让您更容易理解 TextBox,例如,如果我这样做的话:

var myInt = (int)textBox1.text;

例如,这会编译,因为我暗示我希望 myInt 存储一个 Int32 值,但是:

var myInt = (int)textBox1;

将失败,因为您无法将 Object(即 TextBox)转换为 Value 这是否使您更容易看到初始错误的位置以及原因得到它。

这也与 WinFormsWPF 无关,如果基本上是一些简单的事情,我相信我们中的许多人以前都做过,因为我们忘记了附加 。当我们想要转换对象持有的 Value 而不是对象本身

时,文本 到对象的末尾

关于c# - 比较数据网格中同一行的两个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15813266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com