C#winform,如何在一个或多个DataGridView中设置DataGridView VirtualMode

时间:2013-05-21 07:47:50

标签: c# winforms datagridview virtualmode

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

我想将两个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)
    {
        ...
    }

0 个答案:

没有答案