在datagridview中显示新添加的行 [英] showing newly added row in datagridview

查看:281
本文介绍了在datagridview中显示新添加的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在winform应用程序中有一个datagridview,它从外部dll获取数据并动态显示.
随着新行的添加,我想向用户显示新添加的行(以便旧行继续向上移动).
我正在添加新行并显示最后添加的行,如下所示

I have a datagridview in a winform application, that gets data from an external dll and displays it dynamically.
As the new rows are getting added I want to show the newly added row to the user (so that the old rows keep moving upwards).
I am adding the new rows and showing the last added row as follows

string[] currentRow = new string[5];
currentRow[0] = curr.sequence().ToString();
currentRow[1] = typeString;
currentRow[2] = curr.stat().ToString();
currentRow[3] = detail;
currentRow[4] = curr.timestamp().ToString();

this.dataGridView1.Rows.Add(currentRow);
this.labelCount.Text = curr.sequence().ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[curr.sequence()-1].Cells[0]; //exception occurs here


我遇到了
的例外


I am getting an exception of

[System.ArgumentOutOfRangeException] = {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}.

在设置CurrentCell的那一行.
尽管它每次都出现在随机行中.有时它发生在第25行.其他时间排在第1000行.
可能是什么原因造成的?我看到该序列正确显示在labelbox上.
请帮忙.

在此先感谢

at the line where I set the CurrentCell.
Although it occurly at random rows everytime. Sometime it occurs as early as 25th row. Other times at 1000th row.
What could be causing it? I see that the sequence is displayed correctly at labelbox.
Please help.

Thanks in advance

推荐答案

我看不到代码中的"curr"是什么?
I don''t see what "curr" is in your code?


这篇关于在datagridview中显示新添加的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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