DataGridView控件用法合集(四)
19. DataGridView中的ContextMenuStrip属性
20. DataGridView指定滚动框位置
21. DataGridView手动追加列
22. DataGridView全体分界线样式设置
23. DataGridView根据单元格属性更改显示内容
24. DataGridView新追加行的行高样式设置る
25. DataGridView新追加行单元格默认值设置
19. DataGridView中的ContextMenuStrip属性
[C#]
DataGridView1.ContextMenuStrip = this.ContextMenuStrip1
DataGridView1.Columns[0)].ContextMenuStrip = this.ContextMenuStrip2
DataGridView1.Columns[0].HeaderCell.ContextMenuStrip = this.ContextMenuStrip2
DataGridView1.Rows[0].ContextMenuStrip = this.ContextMenuStrip3
DataGridView1[1, 0].ContextMenuStrip = this.ContextMenuStrip4
也可以用CellContextMenuStripNeeded、RowContextMenuStripNeeded属性进行定义
[C#]
20. DataGridView指定滚动框位置
[C#]
DataGridView1.FirstDisplayedScrollingRowIndex = 0
DataGridView1.FirstDisplayedScrollingColumnIndex = 0
21. DataGridView手动追加列
[C#]
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = BindingSource1
DataGridViewTextBoxColumn textColumn=new DataGridViewTextBoxColumn()
textColumn.DataPropertyName = "Column1"
textColumn.Name = "Column1"
textColumn.HeaderText = "Column1"
DataGridView1.Columns.Add(textColumn)
22. DataGridView全体分界线样式设置
[C#]
DataGridView1.BorderStyle = BorderStyle.Fixed3D
单元格上下左右分界线样式设置
[C#]
DataGridView1.AdvancedCellBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.InsetDouble
DataGridView1.AdvancedCellBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.Inset
DataGridView1.AdvancedCellBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.Inset
DataGridView1.AdvancedCellBorderStyle.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble
23. DataGridView根据单元格属性更改显示内容
如下例,当该列是字符串时,自动转换文字大小写
[C#]
24. DataGridView新追加行的行高样式设置
行高设置
[C#]
DataGridView1.RowTemplate.Height = 50
DataGridView1.RowTemplate.MinimumHeight = 50
样式设置
[C#]
'设置背景色为黄色
DataGridView1.DefaultCellStyle.BackColor = Color.Yellow
25. DataGridView新追加行单元格默认值设置
[C#]