• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

Complete ListView

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
1                      
processor              
500
2                        
Scanner                
200                  // Plz remove this Problem here i do not use title plz tell me also about title of listview

My code is this :

try
{
      OleDbDataAdapter data = new OleDbDataAdapter("Select * FROM Stock",strConn);
      DataSet ds = new DataSet();
      data.Fill(ds,"Stock");
     DataTable dtable = ds.Tables["Stock"];
    listView1.Items.Clear();
   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
      listView1.Items.Add(lvi);
      listView1.Items.Add(lvi1);
      listView1.Items.Add(lvi2);
      listView1.Items.Add(lvi3);
      listView1.Items.Add(lvi4);
      listView1.Items.Add(lvi5);
         }
}
0
Mohammad Aamir Qureshi
Asked:
Mohammad Aamir Qureshi
  • 3
  • 2
1 Solution
 
Mohammad Aamir QureshiAuthor Commented:
hello itsvtk , ToAom and TheAvenger

i m waiting for ur response because most of the my questions answer was given by u all
0
 
Mohammad Aamir QureshiAuthor Commented:
Hello itsvtk and ToAom if u r there(online) then plz help me thankx
0
 
dunglaCommented:
You must add stock_name and stock price as sub item of stock_id. Here is example:

try
{
      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");
      adapter.Fill(tblData);
      foreach (DataRow drowData in tblData.Rows)
      {
            // add id first
            ListViewItem item = new ListViewItem(drowData["EmployeeID"].ToString());
            // add sub item
            item.SubItems.Add(drowData["FirstName"].ToString());
            item.SubItems.Add(drowData["LastName"].ToString());
            // add item to list view
            lvData.Items.Add(item);
      }
}
catch (Exception ex)
{
      MessageBox.Show(ex.Message);
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dunglaCommented:
First, you must setup your listview to have 3 colums, and View property of ListView set to Detail
0
 
sourabhkothariCommented:
you'll have to use something like if you have multiple columns

listview1.items[0].subitems.add(lvi1)
listview1.items[0].subitems.add(lvi2)
listview1.items[0].subitems.add(lvi3)

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

Skot
0
 
Mohammad Aamir QureshiAuthor Commented:
Thanks

my problem has solved

once Again Thank
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now