【问题标题】:DoubleClick on DataGridView to get more informations双击 DataGridView 以获取更多信息
【发布时间】:2017-05-07 10:15:28
【问题描述】:

有没有人知道如何制作,当您双击 DataGridView 中的一个单元格时,会出现一个包含更多信息的消息框。因此,例如,我希望我的 DataGridView 仅显示姓名和姓氏,但是当您双击它时,会出现一个消息框,其中包含更多信息,例如年龄、身高...

感谢您的帮助!

【问题讨论】:

  • 为 DGV 的 CellDoubleClick 事件编码!它具有单击单元格的行和列索引。

标签: c# datagridview


【解决方案1】:

首先,您需要像这样订阅“CellDoubleClick”事件:

yourDataGridView.CellDoubleClick += yourDataGridView_CellDoubleClick();

这将使您的程序开始监听双击。在同一个类中,您必须定义双击 DataGridView 时所需的行为。 DataGridViewCellEventArgs 参数具有当前行 (e.RowIndex) 和当前列 (e.ColumnIndex) 的值。这是使用我的 DataGridView 之一的示例:

private void dgvContacts_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
        //Make sure that the user double clicked a cell in the main body of the grid.
        if (e.RowIndex >= 0) {
            //Get the current row item.
            Contact currentContact = (Contact)dgvContacts.Rows[e.RowIndex].DataBoundItem;
            //Do whatever you want with the data in that row.
            string name = currentContact.Name;
            string phoneNum = currentContact.Phone;
            string email = currentContact.Email;
            MessageBox.Show("Name: " + name + Environment.NewLine +
                "Phone number: " + phoneNum + Environment.NewLine +
                "Email: " + email);
        }//if
    }//dgvContacts_CellDoubleClick

【讨论】:

    猜你喜欢
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-30
    • 2015-01-26
    • 2011-01-05
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多