我正在使用devexpress 16.1,我将数据表绑定到xtragrid,
现在我想在单击列标题时按列选择,如果有任何选项可以通过xtragrid实现。
这些都是尝试过的,
gridview1.optionsselection.multiselect = True
gridview1.optionsselection.multiselectMode = cellselect
最佳答案
尝试以下代码:(使用Gridcontrol鼠标按下事件)
VB.net:
Dim hitInfo = GridView1.CalcHitInfo(e.Location)
If e.Button = Windows.Forms.MouseButtons.Left Then
For Each column As GridColumn In GridView1.Columns
If column.FieldName = hitInfo.Column.FieldName Then
hitInfo.Column.AppearanceCell.BackColor = Color.FromArgb(226, 234, 253)
Else
GridView1.Columns(column.FieldName).AppearanceCell.BackColor = Nothing
End If
Next
End If
C#:
var hitInfo = GridView1.CalcHitInfo(e.Location);
if (e.Button == Windows.Forms.MouseButtons.Left)
{
foreach (GridColumn column in GridView1.Columns)
{
if (column.FieldName == hitInfo.Column.FieldName)
{
hitInfo.Column.AppearanceCell.BackColor = Color.FromArgb(226, 234, 253);
}
else
{
GridView1.Columns(column.FieldName).AppearanceCell.BackColor = null;
}
}
}
调用GridView.CalcHitInfo方法以获得行句柄。然后将焦点移至该行,并调用自定义上下文菜单。