如何在WPF DataGrid模板列中设置显示列索引? [英] How to set display column index in wpf datagrid template column?

查看:326
本文介绍了如何在WPF DataGrid模板列中设置显示列索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

在我的程序datagrid中,我添加了一个模板列

xmal-

hi friends,

in my program datagrid, i add a template column

xmal -

<my:datagrid.columns xmlns:my="#unknown">

    <my:datagridtemplatecolumn header="Status" width="110">
        <my:datagridtemplatecolumn.celltemplate>
            <datatemplate>
                <wrappanel name="DG_warpPanel">
                    <Button Width="50" Height="30" Name="DG_btn_Upload" Click="DG_btn_Upload_Click">
                        <Image Width="50" Height="26" Source="Image/Tick.png" />
                    </Button>
                    <Button Width="50" Height="30" Name="Dg_btn_Remove" Click="Dg_btn_Remove_Click">
                        <Image Width="50" Height="26" Source="Image/delete.png" />
                    </Button>
                </wrappanel>
            </datatemplate>
        </my:datagridtemplatecolumn.celltemplate>
    </my:datagridtemplatecolumn>
</my:datagrid.columns>



c#代码-



c# code -

dataGrid1.DataContext = from re in MainWindow.mcsEntity.mcs_image
                             where re.mcs_Image_Code == txt_Code.Text
                             select new
                             {
                                 Id = re.mcs_Image_Id,
                                 Image = re.mcs_Image_Image,
                                 Location = re.mcs_Image_LocationMap
                             };



现在它给出了输出

现状ID |图片|位置.

但我要身份证|图片|位置|状态

我看到了一个适当的展示索引.如何设置这个.

因此,请给我任何想法.



now it give the output

Status | Id | Image | Location.

but i want Id | Image | Location | Status

I saw one propriety Display Index,. how to set this,.

so give me any idea,.

推荐答案

您需要在数据模板中添加四个文本框.
< Stackpanel Orientation ="Horizo​​ntal">
< Grid>
< TextBox文本="{Binding Status}"/>
< TextBox Text ="{Binding Id}"/>
....
</StackPanel>
</DataTemplate>
You need to add four textboxes in your datatemplate.
<Stackpanel Orientation="Horizontal">
<Grid>
<TextBox Text ="{Binding Status}"/>
<TextBox Text = "{Binding Id}"/>
....
</StackPanel>
</DataTemplate>


我尝试为我的问题寻求帮助.但是WPF专家没有给我解决方案.(所有人都这么忙吗?).

我尝试找到解决方案.我希望这段代码对wpf datagrid中存在相同问题的人有所帮助.


I try to get help for my problem. but wpf experts not give me the solution.(All are so busy?).

I try and find the solution. i hope this code help who have the same problem in wpf datagrid.


 if (columnCount == 4)
{
     dataGrid1.Columns[0].DisplayIndex = 3;
     dataGrid1.Columns[1].DisplayIndex = 0;
     dataGrid1.Columns[2].DisplayIndex = 1;
     dataGrid1.Columns[3].DisplayIndex = 2;
}



非常感谢你.



thank u very much.


这篇关于如何在WPF DataGrid模板列中设置显示列索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆