---
1.
DataTable dtZeitplan = new DataTable();
foreach (ColumnHeader chZeitplan in lvZeitplan.Columns)
{
dtZeitplan.Columns.Add(chZeitplan.Text);
}
foreach (ListViewItem item in lvZeitplan.Items)
{
DataRow row = dtZeitplan.NewRow();
for(int i = 0; i < item.SubItems.Count; i++)
{
row[i] = item.SubItems[i].Text;
}
dtZeitplan.Rows.Add(row);
}
2.
if (listView1.Items.Count > 0)
{
dt.Columns.Add();
foreach (ListViewItem.ListViewSubItem lvsi in listView1.Items[0].SubItems)
dt.Columns.Add();
//now we have all the columns that we need, let's add rows
foreach (ListViewItem item in listView1.Items)
{
List<string> row = new List<string>();
row.Add(item.ToString());
foreach (var it in item.SubItems)
row.Add(it.ToString());
//Add the row into the DataTable
dt.Rows.Add(row.ToArray());
}
}
3.
DataTable table = new DataTable();
table.Columns.Add("MODUL", typeof(string));
table.Columns.Add("ACIKLAMA", typeof(string));
table.Columns.Add("UZUNLUK", typeof(string));
table.Columns.Add("GENISLIK", typeof(string));
table.Columns.Add("MIKTAR", typeof(string));
for (int i = 0; i < listView2.Items.Count; i++)
{
table.Rows.Add(listView2.Items[i].SubItems[1].Text, listView2.Items[i].SubItems[2].Text, listView2.Items[i].SubItems[3].Text, listView2.Items[i].SubItems[4].Text, listView2.Items[i].SubItems[5].Text);
}
4.
DataView theDataView = (DataView)theListView.ItemsSource;
DataTable theDataTable = theDataView.Table;
5.
Dim it As Integer = 0
Dim dt As New DataTable
For it = 0 To LVActions.Items(0).SubItems.Count ‑ 1
Dim DCOL As New DataColumn(LVActions.Columns(it).Text)
dt.Columns.Add(DCOL)
Next
For it = 0 To LVActions.Items.Count ‑ 1
Dim DROW As DataRow = dt.NewRow
For j As Integer = 0 To LVActions.Items(it).SubItems.Count ‑ 1
DROW(LVActions.Columns(j).Text) = LVActions.Items(it).SubItems(j).Text
Next
dt.Rows.Add(DROW)
Next
沒有留言:
張貼留言