开发者

Dynamic data matrix WPF

I want to create a completely dynamic data matrix. For eg,

       Column1 Column2 Column3....
id1      id11    id12     id13...
id2      id21    id22     id23...
.         .        .        .
.         .        .        .

Can anybody help me with the code in XAML that will displ开发者_JS百科ay the data in the above manner? I mean I am not sure if I should be using listview or datagrid or anything else to display the data.So if anybody could use some example code and help me out with it..


You could probably use my answer to this Question. It's a subclassed DataGrid used to display, edit and databind 1D or 2D arrays and lists of dynamic size. It can be downloaded from here.

Say you have this 2D array of strings as a Property

public string[][] String2DArray { get; set; }

then you can bind it to the DataGrid2D by adding a reference to the DataGrid2DLibrary.dll and add the namespace

xmlns:dg2d="clr-namespace:DataGrid2DLibrary;assembly=DataGrid2DLibrary"

<dg2d:DataGrid2D Name="c_dataGrid2D" 
                 UseModifiedDataGridStyle="True" 
                 ItemsSource2D="{Binding String2DArray}"/>

And the Output will look like this

Dynamic data matrix WPF


This article mainly shows how to bind a WPF ListView to a DataMatrix (an undefined data source with dynamic columns) where the ListView columns cannot be determined until runtime.

http://www.codeproject.com/KB/WPF/WPF_DynamicListView.aspx


You can try this article on Binding a ListView to a DataMatrix

Dynamic data matrix WPF


Yeah, it sounds like you could make very good use of the <Grid> tag. So, to replicate your example:

<Grid>  
<Grid.ColumnDefinitions>
  <ColumnDefinition Width="100" />
  <ColumnDefinition Width="100" />
  <ColumnDefinition Width="100" />
  <ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
  <RowDefinition Height="25" />
  <RowDefinition Height="25" />
  <RowDefinition Height="25" />
  <RowDefinition Height="25" />
  <RowDefinition Height="25" />
</Grid.RowDefinitions>

<TextBlock Grid.Column="1" Grid.Row="0">Column1</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="0">Column2</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="0">Column3</TextBlock>

<TextBlock Grid.Column="0" Grid.Row="1">id1</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1">id11</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="1">id12</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="1">id13</TextBlock>

<TextBlock Grid.Column="0" Grid.Row="2">id2</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="2">id21</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="2">id22</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="2">id23</TextBlock>

<TextBlock Grid.Column="0" Grid.Row="3">.</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="3">.</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="3">.</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="3">.</TextBlock>

<TextBlock Grid.Column="0" Grid.Row="4">.</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="4">.</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="4">.</TextBlock>
<TextBlock Grid.Column="3" Grid.Row="4">.</TextBlock>

</Grid>

You can also use the WPF datagrid, available in WPF 4.0. If you cannot use the 4.0 Framework, than you still could use the datagrid under the codeplex release for .NET 3.5 SP1. See WPF Toolkit

You could also use the ListView, yes. WPF is very flexible, so you have a lot of choices. Program Grid tags as above, or use a datagrid or listBox or listView with an ItemSource set on the 3 latter choices.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜