none
Error message:" system.windows.listviewitem does not contains a constructor that takes one argument" when trying to add string rrays in listviewitems

    Question


  •  
                string[] product_info = new string[7];
     
                while (dr.Read())
     
                {
     
                    product_info[1] = (dr["product_id"].ToString());
     
                    product_info[2] = (dr["product_name"].ToString());
     
     
                    this.listView1.Items.Add(new ListViewItem(new string[] { product_info[1], product_info[2]}));
     
                }
     
                
    Monday, September 17, 2012 11:13 PM

Answers

  • soom soom

    you are in a wrong path, you are sending string as parameters to listboxitem.

    listboxitem as content property where the value is use to display, follow my below code.

                                                                       
                    string[] product_info = new string[7];
    
                    while (dr.Read())
                    {
    
                        product_info[1] = (dr["product_id"].ToString());
    
                        product_info[2] = (dr["product_name"].ToString());
    
    
                        this.listView1.Items.Add(new ListViewItem{ Content = product_info[1] + product_info[2] });
    
                    }
     


    • Edited by Syed Amjad (MCC) Tuesday, September 18, 2012 8:21 AM
    • Marked as answer by soomsoom Tuesday, September 18, 2012 11:41 AM
    Tuesday, September 18, 2012 8:21 AM

All replies

  • Hi mate, I hope you're fine.

    I believe you may find an appropriate solution for your problem in the following link:

    http://www.c-sharpcorner.com/forums/thread/112597/listviewitem

    I hope this helps.


    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."
    SP Nuke

    • Proposed as answer by dhampall_79 Tuesday, September 18, 2012 11:20 AM
    Tuesday, September 18, 2012 6:50 AM
  • soom soom

    you are in a wrong path, you are sending string as parameters to listboxitem.

    listboxitem as content property where the value is use to display, follow my below code.

                                                                       
                    string[] product_info = new string[7];
    
                    while (dr.Read())
                    {
    
                        product_info[1] = (dr["product_id"].ToString());
    
                        product_info[2] = (dr["product_name"].ToString());
    
    
                        this.listView1.Items.Add(new ListViewItem{ Content = product_info[1] + product_info[2] });
    
                    }
     


    • Edited by Syed Amjad (MCC) Tuesday, September 18, 2012 8:21 AM
    • Marked as answer by soomsoom Tuesday, September 18, 2012 11:41 AM
    Tuesday, September 18, 2012 8:21 AM