{
//行头的ContextMenuStrip设定
e.ContextMenuStrip = this.ContextMenuStrip2;
}
else if (dgv[e.ColumnIndex, e.RowIndex].Value is int)
{
//如果单元格值是整数时
e.ContextMenuStrip = this.ContextMenuStrip3;
}
}
同样,可以通过RowContextMenuStripNeeded事件来设定行的右键菜单。
[VB.NET]
'RowContextMenuStripNeeded事件处理方法
Private Sub DataGridView1_RowContextMenuStripNeeded( _
ByVal sender As Object, _
ByVal e As DataGridViewRowContextMenuStripNeededEventArgs) _
Handles DataGridView1.RowContextMenuStripNeeded
Dim dgv As DataGridView = CType(sender, DataGridView)
'当"Column1"列是Bool型且为True时、设定其的ContextMenuStrip
Dim boolVal As Object = dgv("Column1", e.RowIndex).Value
Console.WriteLine(boolVal)
If TypeOf boolVal Is Boolean AndAlso CBool(boolVal) Then
e.ContextMenuStrip = Me.ContextMenuStrip1
End If
End Sub
[C#]
//RowContextMenuStripNeeded事件处理方法
private void DataGridView1_RowContextMenuStripNeeded(object sender,
DataGridViewRowContextMenuStripNeededEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
//当"Column1"列是Bool型且为True时、设定其的ContextMenuStrip
object boolVal = dgv["Column1", e.RowIndex].Value;
Console.WriteLine(boolVal);
if (boolVal is bool && (bool)boolVal)
{
e.ContextMenuStrip = this.ContextMenuStrip1;
}
}
CellContextMenuStripNeeded事件处理方法的参数中、「e.ColumnIndex=-1」表示行头、「e.RowIndex=-1」表示列头。RowContextMenuStripNeeded则不存在「e.RowIndex=-1」的情况。
--------------------------------------------------------------------------------
⑮ DataGridView 的单元格的边框、 网格线样式的设定
GO TO TOP
1) DataGridView 的边框线样式的设定
DataGridView 的边框线的样式是通过 DataGridView.BorderStyle 属性来设定的。 BorderStyle 属性设定值是一个
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-50089-15.html
这教授也是被骂得惨
撞也不好撞