Hi Iam using winforms-vs2015-c#. I have small application, and I try to display the listview with images I get struck. Actually the table column contains Images. Also when I display the table datasource to DataGridView the Image columns displays the Images very nice. But I wish to use it from listview
C#:
for (int N1 = 0; N1 <= MyDtaTbl.Rows.Count - 1; N1++) {
ChkItm = String.Empty;
ChkItm = MyDataTbl.Rows[N1]["item_type"].ToString().Trim().ToUpper();
Naomi = ChkItm.StartsWith(thisBox.Text);
//MessageBox.Show(thisBox.Text);
if (Naomi == true) {
ListViewItem^ xItem = gcnew ListViewItem(MyDataTbl.Rows[N1]["item_type"].ToString());
//xItem.ImageIndex = 0;
xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_description"].ToString());
xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_code"].ToString());
xItem.SubItems.Add(MyDataTbl.Rows[N1]["type_code"].ToString());
//MyTries
//ListViewItem.ListViewSubItem yItem = new ListViewItem.ListViewSubItem();
//xItem.SubItems.Add(yItem);
//String MyStr = Convert.ToBase64String(MyDataTbl.Rows[N1]["item_image"]);
//Byte[] MyImgBInData = MyDataTbl.Rows[N1]["item_image"];
if (MyDataTbl.Rows[N1]["item_image"] != nullptr && MyDataTbl.Rows[N1]["item_image"] != DBNull.Value) {
//MyParImg = MyDataTbl.Rows[N1]["item_image"].ToBitmap();
//MyParImg = (Bitmap)(MyDataTbl.Rows[N1]["item_image"]);
//MyParImg = MyDataTbl.Rows[N1]["item_image"];
MyParaObject = MyDataTbl.Rows[N1]["item_image"];
}
//xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_image"].ToString());
//xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_image"]); ????????????????????????? Try to add Image Column to Listview
xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_units"].ToString());
xItem.SubItems.Add(MyDataTbl.Rows[N1]["item_rate"].ToString());
listView1.Items.Add(xItem);
}
}
}
Last edited by a moderator: