Complete ListView

Posted on 2005-04-07
Last Modified: 2012-05-05
Hello Experts

plz tell me how can i show complete information that obtain from database and appear in List View

My table name is Stock having three attribute
(1 ) Stock_id
(2) Stock_Name
(3) Stock_Price

my question is this when i use the column header all the information of all three attribute appear in only one column
for e.g

stock_id               stock_Name           stock_price
1                         processor              500
2                         Scanner                 200

and when i write the code its seem like this

stock_id               stock_Name           stock_price
200                  // Plz remove this Problem here i do not use title plz tell me also about title of listview

My code is this :

      OleDbDataAdapter data = new OleDbDataAdapter("Select * FROM Stock",strConn);
      DataSet ds = new DataSet();
     DataTable dtable = ds.Tables["Stock"];
   for (int i = 0; i < dtable.Rows.Count; i++)
        DataRow drow = dtable.Rows[i];

      // Only row that have not been deleted
      if (drow.RowState != DataRowState.Deleted)
               // Define the list items
      ListViewItem lvi = new ListViewItem(drow["Stock_id"].ToString());
      ListViewItem lvi1 = new ListViewItem(drow["Stock_Name"].ToString());
      ListViewItem lvi2 = new ListViewItem(drow["Stock_quantity"].ToString());
      ListViewItem lvi3= new ListViewItem(drow["Stock_Company"].ToString());
      ListViewItem lvi4 = new ListViewItem(drow["Stock_Price"].ToString());
      ListViewItem lvi5= new ListViewItem(drow["Stock_Serial"].ToString());

            // Add the list items to the ListView
    LVL 2

    Author Comment

    by:Mohammad Aamir Qureshi
    hello itsvtk , ToAom and TheAvenger

    i m waiting for ur response because most of the my questions answer was given by u all
    LVL 2

    Author Comment

    by:Mohammad Aamir Qureshi
    Hello itsvtk and ToAom if u r there(online) then plz help me thankx
    LVL 13

    Expert Comment

    You must add stock_name and stock price as sub item of stock_id. Here is example:

          string strSql = "SELECT EmployeeID, FirstName, LastName FROM Employees";
          OleDbConnection cn = new OleDbConnection(CONNECTION_STRING);
          OleDbDataAdapter adapter = new OleDbDataAdapter(strSql, cn);
          DataTable tblData = new DataTable("Employees");
          foreach (DataRow drowData in tblData.Rows)
                // add id first
                ListViewItem item = new ListViewItem(drowData["EmployeeID"].ToString());
                // add sub item
                // add item to list view
    catch (Exception ex)
    LVL 13

    Accepted Solution

    First, you must setup your listview to have 3 colums, and View property of ListView set to Detail
    LVL 1

    Expert Comment

    you'll have to use something like if you have multiple columns


    the above code is to fill the 1st item of the listview having three columns with lvi1,lvi2 and lvi3

    LVL 2

    Author Comment

    by:Mohammad Aamir Qureshi

    my problem has solved

    once Again Thank

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now