1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

how to separate data in the list view

Discussion in 'C#' started by lieweffect, Jun 12, 2006.

  1. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    I have create a list view which contains 4 columns
    I write the code below:

    ListViewBookRecord.Items.Add(( dr["bookname"].ToString()));
    ListViewBookRecord.Items.Add(( dr["authorname"].ToString()));
    ListViewBookRecord.Items.Add(( dr["booktype"].ToString()));
    ListViewBookRecord.Items.Add(( dr["price"].ToString()));

    Then all the data fill at the first columns
    I want the different data fill at the different column
    How should I do in order to put the data at the different column?
    Thank You
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    You have to add them as subitems of the currently added item.
     
  3. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
  4. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Yes,I have tried this:
    ListViewBookRecord.SubItems.Add(( dr["ID"].ToString()));
    But it say that
    'System.Windows.Forms.ListView' does not contain a definition for 'SubItems'
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Here is the code for you to add sub items to the list view in C#
    Code:
    ListViewItem LVI = new ListViewItem("Main Item");
    ListViewItem.ListViewSubItem LVIS1 = new ListViewItem.ListViewSubItem(LVI, "SubItem - 1");
    ListViewItem.ListViewSubItem LVIS2 = new ListViewItem.ListViewSubItem(LVI, "SubItem - 2");
    LVI.SubItems.Add(LVIS1);
    LVI.SubItems.Add(LVIS2);
    
    listViewApps.Items.Add(LVI);
    
     
  6. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Thank You
     

Share This Page