0

我正在开发一个 Windows 窗体项目。在我的表单中,我有两个 DataGridView。

我想将两个 DataGridViews 设置为 DataGridView.VirtualMode。

除了像下面这样创建两次代码之外,有没有什么有效的方法来完成这项任务?

寻求您的建议,在此先感谢。

DataGridView dgv1 = new DataGridView();
DataGridView dgv2 = new DataGridView();

ArrayList expense_summary_codes1 = new ArrayList();
Expense_Summary_Code expense_summary_codeInEdit1;
int rowInEdit1 = -1;
bool rowScopeCommit1 = false;

ArrayList expense_summary_codes2 = new ArrayList();
Expense_Summary_Code expense_summary_codeInEdit2;
int rowInEdit2 = -1;
bool rowScopeCommit2 = false;

... ellipsis

    private void dgv_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
    {
        DataGridView dgv = (DataGridView)sender;
        switch(dgv.Name)
        {
             case "dgv1":                     
                 if (e.RowIndex == dgv.RowCount - 1) return;            

                 Expense_Summary_Code expense_summary_codeTmp1 = null;
                 if (e.RowIndex == rowInEdit1)
                 {
                     expense_summary_codeTmp1 = this.expense_summary_codeInEdit1;

                     ...
                 }
                 ...

                 break;
             case "dgv2":
                 if (e.RowIndex == dgv.RowCount - 1) return;            

                 Expense_Summary_Code expense_summary_codeTmp2 = null;
                 if (e.RowIndex == rowInEdit2)
                 {
                     expense_summary_codeTmp2 = this.expense_summary_codeInEdit2;

                     ...
                 }
                 ...

                 break;
        }
    }

    private void dgv_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
    {
        ...
    }
4

0 回答 0