【问题标题】:Double click on DataGridView cell to open a form双击 DataGridView 单元格以打开一个表单
【发布时间】:2016-10-01 03:21:07
【问题描述】:

我有一个名为 ListaDeAlunos 的表单,上面有一个 DataGridView。 当我双击任何单元格时,我想为 ListaDeAlunos 表单上 DataGridView 的选定行打开一个名为 Alunos 的表单,以便我可以编辑记录。我几乎可以使用它,但是 Alunos 表单在打开时没有显示正确的记录。

这是我到目前为止所做的:

在源表单上,我创建了一个名为 Variables 的类 在那个类中,我创建了一个名为 RecordName

public static string
class Variables
{
    public static string RecordName;
}

在源表单上我创建了一个 CellDoubleClick 事件:

    private void tbl_alunosDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {          
        Form Alunos = new Alunos();
        Alunos.MdiParent = this.MdiParent;
        Alunos.Show();
        Variables.RecordName = this.tbl_alunosDataGridView.CurrentRow.Cells[1].Value.ToString();
    }

在第二个表单(将在 DoubleClick 事件中打开的那个)上,我在 Form_Load 事件中有以下代码:

    private void Alunos_Load(object sender, EventArgs e)
    {   
     this.tbl_alunosBindingSource.Filter = string.Format("Nome LIKE '{0}%'", Variables.RecordName);              
    }

关于如何解决这个问题的任何想法?它几乎可以工作了!

【问题讨论】:

    标签: c# datagridview double-click


    【解决方案1】:

    问题解决了!!!

    我所要做的就是把最后一行代码放在最上面。很简单。

    private void tbl_alunosDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {   Variables.RecordName = this.tbl_alunosDataGridView.CurrentRow.Cells[1].Value.ToString();       
        Form Alunos = new Alunos();
        Alunos.MdiParent = this.MdiParent;
        Alunos.Show();        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-17
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多