索引行以防止单元格中误导数据?

发布于 2024-12-02 00:00:33 字数 618 浏览 1 评论 0原文

在 datagridview 中,我通过传入和传出的消息从零开始更新计数器。这些消息具有类型,因此如果发送或发送类型 A 消息,则类型 A 将会递增。我允许用户排序​​,以便用户可以看到发送或接收的消息类型最少或最多。但是,由于我正在更新消息行中的特定单元格,因此一旦对行进行排序,就会出现不同的数字,因此另一个计数器的值将被更改。例如,

我有类型 A、B 和 C。A

有 4 条消息 B 有 6 条消息, C有32条消息。

假设消息类型 C 现在进入,但用户对列进行排序,然后顺序将是

C 32 乙6 A 4.

由于这是订单,我的问题是我正在更新单元格值。因此,在数据网格中,我将更新单元格 [1, 2] 的值。这意味着 A 的计数器将为 5,而 C 的计数器仍为 32,这是不正确的。我知道消息类型是 C,那么是否有某种方法可以对行进行索引,以便我确切地知道要更新哪一行的单元格值而不是更新单元格本身?这会导致一个相当大的错误,并且行没有名称,所以我不知道如何解决这个问题。我正在考虑使用标题单元格的名称并将行的标题单元格设置为 A、B、C,每当输入 C 类型时,我都会查找标题单元格“C”所在的行,然后导航到该列并更新手机号码。

任何见解都值得赞赏。太感谢了!

.NET 3.5 SP1。 -tf.rz

In a datagridview, I have counters being updated starting from zero via messages being sent in and out. These messages have types, so type A would be incremented if a type A message was sent either in or out. I've allowed user sorting so the user can see which types of messages are being sent or received the least or most. However, since I'm updating the specific cell in the row of the message, once you sort the rows, a different number would be there and thus, another counters' value would be changed instead. For example,

I have types A, B, and C.

A has 4 messages
B has 6 messages,
C has 32 messages.

Let's say Message type C is coming in right now, but the user sorts the columns, and then the order would be

C 32
B 6
A 4.

Since this is the order, my problem is that I'm updating the cell value. So in the datagrid, I'd be updating cell [1, 2]'s value. Which means A would then have a counter of 5, and C would still have a counter of 32, which is not true. I know the message type is C, so is there some way to index the rows so I know exactly which row's cell value to update rather than updating the cell itself? This leads to a pretty large error and rows do not have names, so I'm not sure how to approach this problem. I'm thinking of using the header cell's name and setting the header cell of the rows to A, B, C, and whenever type C comes in, I look for which row the headercell 'C' is in, then navigate to the column and update the cell number.

Any insight is appreciated. Thank you so much!

.NET 3.5 SP1.
-tf.rz

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似狗非友 2024-12-09 00:00:33

如果您的 DataGridView 未绑定到任何 DataSource 你应该这样做。这样您就可以更新 DataGridView 的数据源,并且 DataGridView 会为您更新正确的单元格。

如果您的 DataGridView 绑定到 DataSource,您需要更新 DataSource 而不是直接更新 DataGridView。

If your DataGridView is not bound to any DataSource you should do so. That way you can update your the DataGridView's DataSource and the DataGridView takes care of updating the correct cell(s) for you.

If your DataGridView is bound to a DataSource you need to update the DataSource instead of the DataGridView directly.

谎言 2024-12-09 00:00:33

您需要搜索每条消息之后的行。最简单的方法就是迭代

foreach (DataGridViewRow row in dataGridView1.Rows) 

You need to search the rows after every Message. The easiest way is iterating

foreach (DataGridViewRow row in dataGridView1.Rows) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文