CurrentRow.Index无法正常工作 [英] CurrentRow.Index not work properly

查看:79
本文介绍了CurrentRow.Index无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在使用datagridview及其内部的事件按键时遇到问题.

Hello, i have a issue with a datagridview and the event keypress inside of it.

这是我的代码:

private void dgvHC_KeyPress(object sender, KeyPressEventArgs e)
        {
            int indice = -1;
            if (e.KeyChar == (char)13) {
                if (dgvHC.Rows.Count > 0 && !seleccionado)
                {
                    //this.dgvHC.CurrentRow.Selected = true;

                    //e.Handled = true;

                    indice = dgvHC.CurrentRow.Index;
                    MessageBox.Show("indice:"+indice);
                    IdtHistoriaClinica = dgvHC.Rows[indice-1].Cells[1].Value.ToString();
                    //DialogResult = DialogResult.OK;
                }

                if (dgvHC.Rows.Count == 0)
                    MessageBox.Show("No hay registros disponibles.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if (seleccionado)
                    DialogResult = DialogResult.OK;
            }

        }

问题是返回最后一行的索引作为最后第二行.这是一个错误吗?好吧,我希望很快能收到您的答复.预先感谢.

The issue is that returns the index of the last row as the second last row. Is this a bug? well i hope to hear from your answer soon. Thanks in advance.

推荐答案

不确定最后一行"是什么意思. CurrentRow是具有选定单元格或光标的行.

Not sure what you mean by "last row". The CurrentRow is the row with the selected Cell or cursor.

顺便说一句,由于第一行索引为0,所以最后一行的索引为(Count-1).

BTW, the index of the last row is (Count - 1) since the first Row index is 0.


这篇关于CurrentRow.Index无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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