如何转换ListView
为DataTable
?
XAML
<ListView x:Name="listViewUserHUD" ItemsSource="{Binding CollectionUserData}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsSynchronizedWithCurrentItem="True" util:GridViewSort.AutoSort="True" Margin="16,59,15,61">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding FileNumber}" Header="FileNumber" Width="125" util:GridViewSort.PropertyName="FileNumber" />
<GridViewColumn DisplayMemberBinding="{Binding ShiftDate}" Header="ShiftDate" Width="125" util:GridViewSort.PropertyName="ShiftDate"/>
<GridViewColumn DisplayMemberBinding="{Binding TimeCreated}" Header="TimeCreated" Width="125" util:GridViewSort.PropertyName="TimeCreated" />
<GridViewColumn DisplayMemberBinding="{Binding Remarks}" Header="Remarks" Width="350" util:GridViewSort.PropertyName="Remarks" />
</GridView>
</ListView.View>
</ListView>
代码不起作用:
var listView1 = new ListView();
DataTable table = new DataTable();
foreach (ListViewItem item in listView1.Items)
{
table.Columns.Add(item.ToString());
foreach (var it in item.SubItems)
table.Rows.Add(it.ToString());
}
这是我现在拥有的代码,但我正在尝试这样做。每次生成项目时如何转换ListView
为?DataTable
ListView