开发者

Index rows to prevent misleading data in cell?

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 开发者_StackOverflowthere 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


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.


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

foreach (DataGridViewRow row in dataGridView1.Rows) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜