页面:
<dxg:GridControl Name=“gridSource” Grid.Row=“0” AutoPopulateColumns=“True” IsFilterEnabled=“True” >
dxg:GridControl.View
<dxg:TableView Name=“gridSourceView” ShowFilterPanelMode=“Never” ShowAutoFilterRow=“True” AllowEditing=“False” AllowColumnFiltering=“False” AutoWidth=“False” NewItemRowPosition=“None” ShowGroupPanel=“False” ShowTotalSummary=“False”/>
</dxg:GridControl.View>
dxg:GridControl.Columns
<dxg:GridColumn Fixed=“Left” Header=“选择” MinWidth=“60” Width=“60” FieldName=“XX” ImmediateUpdateAutoFilter=“False” AllowAutoFilter=“False” >
dxg:GridColumn.EditSettings
<dxe:CheckEditSettings />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn Fixed="Right" Width="60" FieldName="SH" AllowDrop="False" Header="审核" HorizontalHeaderContentAlignment="Center" ShowInColumnChooser="False" MinWidth="60" >
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Tag="{Binding}" Text="审核" Foreground="Blue" Name="txtSH" Margin="0,2,0,0" Cursor="Hand" MouseLeftButtonUp="txtSH_MouseLeftButtonUp_1" />
</StackPanel>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
后台:
private double gridColumnWidth = 0;
private List<ComItem> binlist = new List<ComItem>();
gridColumnWidth = 0;
this.gridSource.ItemsSource = null;
GridColumn gridColumn = new GridColumn();
gridColumn.Name = "gridColumn" ;
gridColumn.FieldName ="";
gridColumn.Header ="";
gridColumn.ImmediateUpdateAutoFilter = false;
gridColumn.BestFitArea = BestFitArea.Header;
Bitmap bitmap = new Bitmap(500, 30);
Graphics graphics = Graphics.FromImage(bitmap);
SizeF sizeF = graphics.MeasureString(item.Alias, new Font("宋体", 9));
gridColumn.MinWidth = sizeF.Width + 20;
gridColumnWidth += gridColumn.MinWidth;
gridColumn.CellTemplate = CreateDataTemplate(item);
ComboBoxEditSettings com = new ComboBoxEditSettings();
binlist.Add(new ComItem() { Code = “Y”, Name = “通过” });
com.ItemsSource = binlist;
com.ValueMember = “Code”;
com.DisplayMember = “Name”;
gridColumn.EditSettings = com;
gridColumn.ReadOnly = true;
this.gridSource.Columns.Add(gridColumn);
private DataTemplate CreateDataTemplate(FieldClass fieldClass)
{
if (!fielddic.ContainsKey(fieldClass.Name))
fielddic.Add(fieldClass.Name, fieldClass.FieldValues);
DataTemplate dt = new DataTemplate();
try
{
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(TextBlock));
Binding binding = new Binding();
binding.Path = new PropertyPath(“RowData.Row.” + fieldClass.Name);
binding.Converter = FindResource(“CustomCvt”) as IValueConverter;
binding.ConverterParameter = fieldClass;
fef.SetBinding(TextBlock.TextProperty, binding);
//fef.SetBinding(TextBlock.ToolTipProperty, binding);
fef.SetValue(TextBlock.MarginProperty, new Thickness(2, 1, 0, 0));
dt.VisualTree = fef;
}
catch (Exception EX)
{
}
return dt;
}