如何为devexpress datagrid的每个列单元格制作上下文菜单?
How to make context menu to each column cell at devexpress datagrid?
如何为 devexpress 数据网格中的每个列单元格制作上下文菜单?
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
<dxg:GridControl Grid.Row="0"
Height="150"
ItemsSource="{Binding ObjectViewModel.Collection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding CurrentRow,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,TargetNullValue=null}"
>
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Column1"}"
Width="*"
Binding="{Binding col1,Mode=OneWay}">
</dxg:GridColumn>
<dxg:GridColumn Header="Column2"}
AllowEditing="False"
Width="*"
Binding="{Binding col2,Mode=OneWay}">
<!--<dxg:GridColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Col2!"></MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</dxg:GridColumn.CellStyle>-->
</dxg:GridColumn>
</dxg:GridControl>
如何为每一列制作上下文菜单?
例如,当上下文菜单单击第一列时(在属于第一列的单元格上):它显示 "Column1 menu" 项目和
当它点击第二列时(在属于第二列的单元格上)显示 "Column2 menu" item
我找到了答案:
<dxg:GridControl.View>
<!--region #RowCellMenuCustomization-->
<dxg:TableView x:Name="view" AutoWidth="True">
<dxg:TableView.RowCellMenuCustomizations>
<dxb:BarButtonItem Content="Menu1"
ItemClick="CellDataItem_Menu1_ItemClick"
Glyph="/MyCompany.UI.Resources;component/PNGImages/Menu1.png"
>
</dxb:BarButtonItem>
</dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>
和处理程序:
private void CellDataItem_ByColumn_ItemClick(object sender, ItemClickEventArgs e)
{
var menuInfo = view.GridMenu.MenuInfo as GridCellMenuInfo;
if (menuInfo != null && menuInfo.Row != null)
{
var column = menuInfo.Column as GridColumn;
if (column == null) return;
if ((String)column.ActualColumnChooserHeaderCaption == _nameColumn)//context menu under column "Name"
{
//code here
}
else if(...)
{}
}
}
如何为 devexpress 数据网格中的每个列单元格制作上下文菜单?
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
<dxg:GridControl Grid.Row="0"
Height="150"
ItemsSource="{Binding ObjectViewModel.Collection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding CurrentRow,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,TargetNullValue=null}"
>
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Column1"}"
Width="*"
Binding="{Binding col1,Mode=OneWay}">
</dxg:GridColumn>
<dxg:GridColumn Header="Column2"}
AllowEditing="False"
Width="*"
Binding="{Binding col2,Mode=OneWay}">
<!--<dxg:GridColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Col2!"></MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</dxg:GridColumn.CellStyle>-->
</dxg:GridColumn>
</dxg:GridControl>
如何为每一列制作上下文菜单?
例如,当上下文菜单单击第一列时(在属于第一列的单元格上):它显示 "Column1 menu" 项目和 当它点击第二列时(在属于第二列的单元格上)显示 "Column2 menu" item
我找到了答案:
<dxg:GridControl.View>
<!--region #RowCellMenuCustomization-->
<dxg:TableView x:Name="view" AutoWidth="True">
<dxg:TableView.RowCellMenuCustomizations>
<dxb:BarButtonItem Content="Menu1"
ItemClick="CellDataItem_Menu1_ItemClick"
Glyph="/MyCompany.UI.Resources;component/PNGImages/Menu1.png"
>
</dxb:BarButtonItem>
</dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>
和处理程序:
private void CellDataItem_ByColumn_ItemClick(object sender, ItemClickEventArgs e)
{
var menuInfo = view.GridMenu.MenuInfo as GridCellMenuInfo;
if (menuInfo != null && menuInfo.Row != null)
{
var column = menuInfo.Column as GridColumn;
if (column == null) return;
if ((String)column.ActualColumnChooserHeaderCaption == _nameColumn)//context menu under column "Name"
{
//code here
}
else if(...)
{}
}
}