I want to insert list view subitems in wpf.
I am using this code to insert subitems in windows form listview,
con.Open();
DataTable dt = new DataTable();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter("select * from test where (SecSym='" + secsym + "')", con);
da = new OleDbDataAdapter("select * from test where (SecSym='" + secsym + "')order by Date desc", con);
da.Fill(dt);
int iRecords = 0;
foreach (DataRow myrow in dt.Rows)
{
ListViewItem lItem = new ListViewItem();
lItem.UseItemStyleForSubItems = false;
DateTime Date = DateTime.ParseExact(myrow[3].ToString(), "yyyyMMdd", CultureInfo.CurrentCulture);
string date = Date.ToString("ddd, dd-MMM-yyyy");
lItem = listviewTargets.Items.Insert(iRecords, date);
lItem.UseItemStyleForSubItems = false;
// listviewTargets.Items.Add(myrow[2].ToString());
lItem.SubItems.Add(myrow[1].ToString());
lItem.SubItems.Add(myrow[15].ToString());
lItem.SubItems.Add(myrow[5].ToString(), Color.White, Color.Green, lItem.Font);
lItem.SubItems.Add(myrow[7].ToString());
lItem.SubItems.Add(myrow[8].ToString());
lItem.SubItems.Add(myrow[9].ToString());
lItem.SubItems.Add(myrow[10].ToString());
iRecords++;
lItem = listviewTargets.Items.Insert(iRecords, "");
lItem.UseItemStyleForSubItems = false;
lItem.SubItems.Add("");
lItem.SubItems.Add("");
lItem.SubItems.Add(myrow[6].ToString(), Color.White, Color.Red, lItem.Font);
lItem.SubItems.Add(myrow[11].ToString());
lItem.SubItems.Add(myrow[12].ToString());
lItem.SubItems.Add(myrow[13].ToString());
lItem.SubItems.Add(myrow[14].ToString());
iRecords++;
}
con.Close();
But I don’t know how to insert subitems in wpf listview.
There would be a great appreciation if someone could me.
Thanks In Advance.
The WPF Listview is a bit different and has no “SubItems”
You could achieve your goal as follows:
Define the Listview in xaml (with databindings to the collection):
CodeBehind of this example: