Results 1 to 3 of 3

Thread: listview equivalent to VB6 listindex

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    Question listview equivalent to VB6 listindex

    I am trying to get the following VB6 listindex to work within my vb.net code:
    Code:
        setTheR CStr(payReq.ItemData(payReq.ListIndex))
    But if i copy and paste that into VB.net it wont accept it.

    This is what VB.net did with the converting of the VB6 to .net code:
    Code:
        strContract = payReq.Items.Item(payReq.FocusedItem.Index).Text
    However, checking that value it returns the name instead of the index. While the VB6 code returns the value of 2311 (which is what it needs to return)

    When i add items to the listview i do this:
    Code:
        Item = payReq.Items.Add(rsPayRequests.Fields("userid").Value)
        Item.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing,   VB6.Format(rsPayRequests.Fields("reqdatetime").Value, "mm/dd/yyyy")))
    But i noticed it does this as well:
    Code:
        payReq.Items.Add(New VB6.ListBoxItem(Item, rsPayRequests.Fields("requestNum").Value))
    But that does not work with my listview in .net since that above is a listbox and not a listview. Is there an equivalent in .net for the listbox to have a custom index?

    Any help would be great!

    David

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: listview equivalent to VB6 listindex

    You say that you want the index of the item. here's your code:
    Code:
    strContract = payReq.Items.Item(payReq.FocusedItem.Index).Text
    You already had the index but then you tried to do something fancy with it. If that's not what you actually want then please explain what you actually wnat. Forget code and talk about functionality. If you know what you want the code to do, then you can write code to do it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    Re: listview equivalent to VB6 listindex

    I got it. Thanks for the reply though, jmcilhinney!

    I ended up using the .tag on the listview itself. It served its perpose just fine.
    Code:
    Item.Tag = payReq.Fields("requestNum").Value
    And i called it by using this (note, its .tag now instead of .value)
    Code:
    strContract = payReq.Items.Item(payReq.FocusedItem.Index).Tag
    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width