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(現在のセルがある行は、新
您可能关注的文档
- 95年建模A题PPT.ppt
- 9 第3章 理想流动均相反应器.pdf
- 9.14看图解盘.doc
- 9 土地税收.ppt
- 9.情态动词.ppt
- 9.情态动词 练习.ppt
- 9A unit1 star sign 笔记.doc
- 9个护肤雷区 你踩中了多少?.docx.doc
- 9年级unit2单元测试题.doc
- 9月19日农场品剖析建议.doc
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
原创力文档

文档评论(0)