以编程方式选择一行DataGridView [英] selecting a row of DataGridView Programatically

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

问题描述

HI ALL .....
在我的表单应用程序中,有一个(buttonNEW)选择DataGridView的NewIndexRow.

HI ALL.....
In my form application , there is a (buttonNEW) that select NewIndexRow of DataGridView.

private void buttonNew_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow.Index!=dataGridView.NewRowIndex)
            {
                dataGridView.ClearSelection();
                dataGridView.Rows[dataGridView.NewRowIndex].Selected = true;
                label1.Text = dataGridView.CurrentRow.Index.ToString();
                
            }
        }


但是单击按钮后,DataGridView的索引不会更改.
是什么问题?.....


but after clicking the button the index of DataGridView does not change.
What is the problem?.....

推荐答案



您需要使用该行作为当前行,但是CurrentRowreadonly,因此设置当前单元格具有所需的效果.

DataGridView.CurrentCell属性 [
Hi,

You need to make use of the row the current row, but CurrentRow is readonly, so setting the current cell has the desired effect.

DataGridView.CurrentCell Property[^]

You could also handle this event:
public event EventHandler SelectionChanged

,如果当前选择已更改,它将通知您.这样,您可以测试所选内容是否已更改.

亲切的问候,

which will notify you if the current selection has changed. This way you can test if the selection has changed.

Kind regards,


这篇关于以编程方式选择一行DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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