WPF dev GridControl 初始化列,GridColumn字段模板更改

页面:
<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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值