在WinForm下,可以将两个C1FlexGrid绑定到DataSet的某个表和这个表上的DataRelation上,方便地实现主-子数据的展现.
在WPF下,我采用相同的方法,但是在移动主表的选择行时,子表中的数据无法刷新,但ListBox可以,请问是何原因?
官方网站的 http://download.componentone.com/pub/Demo/WPF/FlexGrid/FlexGridXBAP.xbap例子中可以实现移动"当前行",但与其提供的下载代码不符,从下载的代码看,是把FlexGrid绑定到ObservableCollection的.请问如果绑定到DataTable或DataView如何实现移动"当前行"?
我使用的是VS2008+C1StudioWPF2011V3
这是xaml代码- <Window x:Class="Window1"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Window1" Height="300" Width="300" xmlns:my="clr-namespace:C1.WPF.FlexGrid;assembly=C1.WPF.FlexGrid">
- <Grid Name="MainLayout">
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="*"/>
- </Grid.ColumnDefinitions>
- <my:C1FlexGrid Name="MainGrid" Grid.Row="0" Grid.Column="0"/>
- <my:C1FlexGrid Name="SubGrid" Grid.Row="0" Grid.Column="1"/>
- <ListBox Name="MainList" Grid.Row="1" Grid.Column="0"/>
- <ListBox Name="SubList" Grid.Row="1" Grid.Column="1"/>
- </Grid>
-
- </Window>
复制代码 这是后台代码- Imports System.Data
- Imports System.Windows.Markup
- Class Window1
- Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
- Dim dtMain As New DataTable("t1"), dtSub As New DataTable("t2")
- Dim ds As New DataSet
- With dtMain.Columns
- .Add("Id", GetType(Integer))
- .Add("MainName", GetType(String))
- End With
- With dtSub.Columns
- .Add("Id", GetType(Integer))
- .Add("MainId", GetType(Integer))
- .Add("SubName", GetType(String))
- End With
- For i As Integer = 1 To 10
- Dim r1 As DataRow = dtMain.NewRow
- r1("Id") = i : r1("MainName") = "MainName" & i
- dtMain.Rows.Add(r1)
- For j As Integer = 1 To i
- Dim r2 As DataRow = dtSub.NewRow
- r2("Id") = (i - 1) * 10 + j
- r2("MainId") = i
- r2("SubName") = "MainName" & i & "_" & "SubName" & j
- dtSub.Rows.Add(r2)
- Next
- Next
- ds.Tables.AddRange(New DataTable() {dtMain, dtSub})
- ds.Relations.Add(New DataRelation("r1", dtMain.Columns("Id"), dtSub.Columns("MainId")))
- MainLayout.DataContext = ds
- MainGrid.SetBinding(C1.WPF.FlexGrid.C1FlexGrid.ItemsSourceProperty, New Binding("t1"))
- SubGrid.SetBinding(C1.WPF.FlexGrid.C1FlexGrid.ItemsSourceProperty, New Binding("t1/r1"))
- With MainList
- .IsSynchronizedWithCurrentItem = True
- .ItemTemplate = XamlReader.Load(<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
- <TextBlock Text="{Binding Path=MainName}"/>
- </DataTemplate>.CreateReader())
- .SetBinding(ListBox.ItemsSourceProperty, New Binding("t1"))
- End With
- With SubList
- .IsSynchronizedWithCurrentItem = True
- .ItemTemplate = XamlReader.Load(<DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
- <TextBlock Text="{Binding Path=SubName}"/>
- </DataTemplate>.CreateReader())
- .SetBinding(ListBox.ItemsSourceProperty, New Binding("t1/r1"))
- End With
- End Sub
- End Class
复制代码 |
|