表只是一个表结构
DataSet1 ds = new DataSet1()
using (SqlConnection conn = new SqlConnection(conString))
{
using (SqlDataAdapter adpt = new SqlDataAdapter("select * from MedicionType", conn))
{
adpt.Fill(ds, "表名,必须和你的数据集里拖出来的一样")
}
}
CrystalReport1 cys = new CrystalReport1()
cys.SetDataSource(ds)
this.crystalReportViewer1.ReportSource = cys
DJI数据文件需使用官方专用查看器打开,下载地址:http://download.dji-innovations.com/downloads/iosd/iOSD_Installer_4.1.exe
表中创建三个字段就可以了(ID,Name,ParentID),然后定义一个对应节点的类,比如:public class TypeNode
{
public string ID{getset}
public string Name{getset}
public TypeNode Parent{getset}
public ObservableCollection<TypeNode>Children{getset}
public bool IsSelected{getset}
}
添加构造节点的方法,根据ID来确定上下级和加载子节点,代码就不列举了;然后实现一下INotifyPropertyChanged接口就差不多了。接着定义几个样式:
<Style x:Key="TypeTreeStyle" TargetType="TreeView">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<ScrollViewer Padding="4" Focusable="False" CanContentScroll="False">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TypeNode" TargetType="TreeViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</Style.Triggers>
</Style>
<HierarchicalDataTemplate x:Key="TypeTreeGroup" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding TypeName}" FontSize="13"/>
</HierarchicalDataTemplate>
在ViewModel或是后台代码中定义一个ObservableCollection<TypeNode>集合,名为TypeTree,在xaml中添加TreeView并绑定:
<TreeView ItemsSource="{Binding TypeTree}"
Style="{StaticResource TypeTreeStyle}"
ItemContainerStyle="{StaticResource TypeNode}"
ItemTemplate="{StaticResource TypeTreeGroup}"/>
根据节点的IsSelected属性来确定在哪个位置创建子节点,同时就得到了数据的ParentID,再加上创建时指定的ID和Name存入数据库就完工了。希望对你有帮助,还有疑问请追问或是Hi
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)