初学者-WPF DataGrid-如何格式化每行中的多行? [英] Beginner - WPF DataGrid - How to Format Mult Rows in each Row?

查看:94
本文介绍了初学者-WPF DataGrid-如何格式化每行中的多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#,WPF和VS的新手.我正在将VBA应用程序转换为C#.
如何创建一个格式化为每个DataGrid行中有多个行的DataGrid?
我似乎找不到任何地方.

请参阅我正在转换的附件的示例.
哎呀看不到如何附加任何东西,因此请参见下文.

屏幕是这样的:

I am new to C#, WPF and VS. I am converting a VBA application to C#.
How do I create a DataGrid with multiple rows within each DataGrid Row formatted?
I can''t seem to find out how anywhere.

See attached sample of what I am converting.
Woops can''t see how to attach anything so see below.

Screen is like this:

Client Details Area as follows
----------------------------------------------------------------------
Name: xxxxxxxxx  Country: xxxxxxx
Ph: xxxxxx Fax: xxxxxx

etc.etc.
----------------------------------------------------------------------
Tab1 | Tab2 | Address Tab | etc. (this is Tab Selector)
=======================================
Address Lines City etc. (this is Data Grid Header)
=======================================
Adr1: Level 10, Unit 120--------Sydney
Adr2: 30 Thingy Lane
Adr3: xxxxxxxxxxx   
--------------------------------------------------------------

上面是数据网格的一行.这将是第二行.

希望您了解我的意思.

The above is one row of the data grid. Here would be the second row.

I hope you understand what I am getting at.

推荐答案

最简单的方法是使用ListView.以下是有关使用它的文章的链接:

http://www.switchonthecode.com/tutorials/wpf-tutorial-using- the-listview-part-1 [ ^ ]

也可以使用ListBox,但是您需要一个DataTemplate,除非您手动创建标题,否则就不会有标题.



我理解你的疑虑.我与Infragistics XmlDataGrid进行了广泛的合作,它可以使用反射来配置ViewModel的网格.缺点是,如果还有其他属性不显示,则必须手动修复,并且对单元格进行某些自定义,然后还必须手动配置. ListView仍然比ListBox更好,因为它为网格视图提供了更好的支持,并提供了列标题.我仍然比其他任何东西都更多地使用了ListBox.显然,Infragistics解决方案需要支付使用网格的权利.还有WPF DataGrid,请参见 WPF DataGrid实用示例 [
The easiest thing would be to use a ListView. The following is a link to an article on using it:

http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1[^]

It is also possible to use a ListBox, but then you need a DataTemplate, and there would be no headers unless you manually created them.



I understand your misgivings. I have worked extensively with the Infragistics XmlDataGrid, and it can use reflection to configure the grid form the ViewModel. The disadvantage is that then, if there are other properties that are not to be displayed, must manually fix, and if there is some customization of a cell, and then also have to manually configure. Still the ListView is better than the ListBox since it provides better support for a grid view, providing column headers, among other things. Still I have used the ListBox more than anything else. Obviously the Infragistics solution requires paying for the rights to use the gird. There is also the WPF DataGrid, see WPF DataGrid Practical Examples[^]


已添加这是因为它是ListView的重要补充. ListView 支持复杂的单元格内容.在这里有一个样本:

Added this since it is a significant addition to ListView. ListView supports complex cell content. Have a sample here:

<window x:class="WpfApplication1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <grid>
    <listview>
      <listview.view>
        <gridview>
          <gridviewcolumn width="120" header="Date">
            <gridviewcolumn.celltemplate>
              <datatemplate>
                <stackpanel>
                  <checkbox />
                </stackpanel>
              </datatemplate>
            </gridviewcolumn.celltemplate>
          </gridviewcolumn>
          <gridviewcolumn width="120" header="Day Of Week">
            DisplayMemberBinding="{Binding DayOfWeek}" />
          <gridviewcolumn width="120" header="Year">
           DisplayMemberBinding="{Binding Year}" />
        </gridviewcolumn></gridviewcolumn></gridview>
      </listview.view>
    </listview>
  </grid>
</window>



如您所见,ListView GridViewColumn 支持模板内容.在这里,我只在内部放置了CheckBox ,但是由于我将其放置在StackPanel中,因此可以轻松地在Stackpanel 内添加更多内容(如果这样更好,请使其成为Grid).取决于您想要的内容.可能会或可能不会有帮助.



As you can see the ListView GridViewColumn suports a template content. Here I only put a CheckBox inside, but since I put this in a StackPanel, easily add more inside the Stackpanel (make it a Grid if that is better). Depends on the content you want. May or may not help.


这篇关于初学者-WPF DataGrid-如何格式化每行中的多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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