以编程方式更改DatagridView(.NET)上的选择 [英] Programmatically change selection on DatagridView (.NET)

查看:41
本文介绍了以编程方式更改DatagridView(.NET)上的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习VB.NET。

I'm learning VB.NET.

在尝试设置CurrentCell的值时,DataGridView组件出现问题。
我想做的是:

I've a problem with DataGridView component when trying to set the value of the CurrentCell. What i'm trying to do is :

我有一个带有值的DataGridView。
我想在表单中创建一个按钮,单击该按钮时,我要将选择内容从当前行更改为下一行。为了进一步说明,通过单击我的按钮,我想模拟在DataGridview上单击鼠标的效果。

I've a DataGridView With values. I want to make a button in my forms and when clicking on it I want to change the selection from the current row to the next. To explain more, by clicking my Button I want to simulate the effect of a mouse click on a DataGridview.

我希望您能为我提供帮助,

I hope you can help me,

谢谢!

推荐答案

也许是这样的:

    If DataGridView1.RowCount > 0 Then

        Dim MyDesiredIndex As Integer = 0

        If DataGridView1.CurrentRow.Index < DataGridView1.RowCount - 1 Then
            MyDesiredIndex = DataGridView1.CurrentRow.Index + 1
        End If

        DataGridView1.ClearSelection()            
        DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)
        DataGridView1.Rows(MyDesiredIndex).Selected = True

    End If

注1:也许这两行不是必需的。我还没有证明

Note 1: maybe these two lines are not necessary. I haven´t proved it

        DataGridView1.ClearSelection()            
        DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)

注意2:请注意,如果我们在最后一行,转到第一行

Note 2: note that if we are in the last row, it goes to first

这篇关于以编程方式更改DatagridView(.NET)上的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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