Question How to display the Images column with listview

Paraman

New member
Joined
Oct 19, 2024
Messages
3
Programming Experience
10+
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:
For the record, the inline code tag is for inline code, e.g. if you're telling someone that you used a TextBox control. If you want to post a block of code, used the code tag. I have edited your post accordingly.
 
There's no such thing as an image column in a ListView. If you want to associate images with items in a ListView, you need to use an ImageList. You should read some relevant documentation, starting here:

 
Not related to your problem: Why are you using VS2015? Upgrade to VS2022.
 

Latest posts

Back
Top Bottom