在datagridview vb.net中选择多行时,有些行没有删除? [英] While selecting multiple rows in datagridview vb.net, some of the row not deleting?

查看:115
本文介绍了在datagridview vb.net中选择多行时,有些行没有删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,



在vb.net的Datagridview中选择多行时,有些行没有删除。
当我删除事件时
的KeyDown)发生。见下文,



示例:

 DataGrid有100行。 

对于项目As Integer = 0 To DataGrid.RowCount - 1 Step 1
If DataGrid.Rows(item).Selected Then
这里的逻辑代码...
---------
---------
结束如果
下一个
我选择5行DataGrid并按删除键,
现在只有4行或更少的行删除
我无法知道剩余的选定行为什么不删除。
请帮帮我。

解决方案

这可能对你有所帮助......



http://stackoverflow.com/questions/14563807/datagridview-multiple -row-selection-issue [ ^ ]


如果您考虑使用

 对于 item 作为整数=  0    DataGrid。 RowCount   -   1 步骤 1  



尝试用行号来描绘它......

 0。第0行选择
1.第1行选择
2.第2行选择
3.第3行选择
4.选择第4行



想象一下,我们正在完成你的循环...以 item = 0 开头 - 你的代码删除第0行...在我们再进一步看之前让我们看一下再次网格... 看起来像这样

  0。选择第0行 
1.第1行选择
2.第2行选择
3.第3行选择
4.选择第4行

我们已经删除了第0行,所以当我们添加行号时,它现在看起来像这样。

 0。第1行选择
1.第2行选择
2.第3行选择
3.选择第4行

item 现在移动到 1 的值,因此您的代码将删除行 1 ,因为网格现在不是您启动时第1行中的内容。



为了解决这个问题,在datagridview的末尾开始循环并向后工作 - 那样你还没有得到的行号是一样的就像你刚开始时一样。



对于项目As Integer = DataGrid.RowCount  -  1 To 0 Step -1 


Hi Team,

While selecting multiple rows in Datagridview in vb.net some rows not deleting.
when I delete event (KeyDown)occur. See below,

Example:

DataGrid having 100 rows.

For item As Integer = 0 To DataGrid.RowCount - 1 Step 1
                    If DataGrid.Rows(item).Selected Then
                    Logic code here... 
                    ---------
                    ---------
                    End If
Next
I am selecting 5 rows in DataGrid and press delete key,
Now only 4 or less rows deleting
I can not able to know remaining selected rows why not deleting.
Please help me.

解决方案

May be this will help you...

http://stackoverflow.com/questions/14563807/datagridview-multiple-row-selection-issue[^]


If you think about that datagridview that your are stepping through using

For item As Integer = 0 To DataGrid.RowCount - 1 Step 1


Try to picture it with row numbers ...

0. Line 0 selected
1. Line 1 selected
2. Line 2 selected
3. Line 3 selected
4. Line 4 selected


Imagine we are going through your loop ... start with item = 0 - your code deletes row 0 ... before we go any further let's look at the grid again ... it doesn't look like this

0. Line 0 selected
1. Line 1 selected
2. Line 2 selected
3. Line 3 selected
4. Line 4 selected

we've deleted row 0 so it now looks like this when we add it the row numbers

0. Line 1 selected
1. Line 2 selected
2. Line 3 selected
3. Line 4 selected

item now moves on to a value of 1 so your code deletes row 1 as the grid now stands NOT what was in row 1 when you started.

To get around this, start your loop at the end of the datagridview and work backwards - that way the row numbers that you haven't got to yet are the same as they were when you started.

For item As Integer = DataGrid.RowCount - 1 To 0 Step -1


这篇关于在datagridview vb.net中选择多行时,有些行没有删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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