DataGridView常见问题解答_2.doc

DataGridView常见问题解答_2

DataGridView控件用法合集 ? 1.当前的性取得[VB.NET] Console.WriteLine(DataGridView1.CurrentCell.Value) Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex) Console.WriteLine(DataGridView1.CurrentCell.RowIndex) DataGridView1.CurrentCell = DataGridView1(0, 0) [C#] Console.WriteLine(DataGridView1.CurrentCell.Value); Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex); Console.WriteLine(DataGridView1.CurrentCell.RowIndex); DataGridView1.CurrentCell = DataGridView1[0, 0]; 2.DataGridView编辑属性 全部单元格编辑属性 [VB.NET] DataGridView1.ReadOnly = True [C#] DataGridView1.ReadOnly = true; 指定行列单元格编辑属性 [VB.NET] DataGridView1.Columns(1).ReadOnly = True DataGridView1.Rows(2).ReadOnly = True DataGridView1(0, 0).ReadOnly = True [C#] DataGridView1.Columns[1].ReadOnly = true; DataGridView1.Rows[2].ReadOnly = true; DataGridView1[0, 0].ReadOnly = true; 根据条件判断单元格的编辑属性 下例中column2的值是True的时候,Column1设为可编辑 [VB.NET] Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, _ ByVal e As DataGridViewCellCancelEventArgs) _ Handles DataGridView1.CellBeginEdit Dim dgv As DataGridView = CType(sender, DataGridView) If dgv.Columns(e.ColumnIndex).Name = Column1 AndAlso _ Not CBool(dgv(Column2, e.RowIndex).Value) Then e.Cancel = True End If End Sub [C#] private void DataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { DataGridView dgv = (DataGridView)sender; if (dgv.Columns[e.ColumnIndex].Name == Column1 !(bool)dgv[Column2, e.RowIndex].Value) { e.Cancel = true; } } 3.DataGridView最下面一列新追加行非表示 [VB.NET] DataGridView1にユーザーが新しい行を追加できないようにする DataGridView1.AllowUserToAddRows = False [C#] //DataGridView1にユーザーが新しい行を追加できないようにする DataGridView1.AllowUserToAddRows = false; 4.判断当前选中行是否为新追加的行 [VB.NET] If DataGridView1.CurrentRow.IsNewRow Then Console.WriteLine(現在のセルがある行は、新しい行です。) Else Console.WriteLine(現在のセルがある行は、新しい行ではありません。) End If [C#] if (DataGridView1.CurrentRow.IsNewRow) Console.WriteLine(現在のセルがある行は、新

文档评论(0)

1亿VIP精品文档

相关文档