CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Posts
    326

    [RESOLVED] Define a ListBox items text.

    Hi,

    Suppose I have a listbox aaa which has two items.
    How to define the text for each item?


    My code is incorrect but not sure why?
    Code:
    aaa.ItemData(0)="Yes"
    aaa.ItemData(1)="No"
    Thanks

  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Define a ListBox items text.

    Try

    aaa.additem "Yes"

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Define a ListBox items text.

    Here's something I did a while back, to illustrate the ListIndex property as well


    Code:
    Option Explicit
    
    Private Sub Combo1_Click()
      Dim msg As String
    '  MsgBox Combo1.Text
      msg = Combo1.ItemData(Combo1.ListIndex) & " "
      msg = msg & Combo1.List(Combo1.ListIndex)
      MsgBox msg
    End Sub
    
    Private Sub Form_Load()
      ' Could also use ' List1.ItemData(0) = 5
      List1.AddItem "David G"
      List1.ItemData(List1.NewIndex) = 42001 ' New Index
      List1.AddItem "Greg G"
      List1.ItemData(List1.NewIndex) = 42000 ' New Index
      Combo1.AddItem "David G"
      Combo1.ItemData(Combo1.NewIndex) = 42001 ' New Index
      Combo1.AddItem "Greg G"
      Combo1.ItemData(Combo1.NewIndex) = 42000 ' New Index
    
    End Sub
    
    Private Sub List1_Click()
    ' Append Name to ItemData
      Dim msg As String
    ' msgbox list1.text
      msg = List1.ItemData(List1.ListIndex) & " "
      msg = msg & List1.List(List1.ListIndex)
      MsgBox msg
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jan 2006
    Posts
    326

    Re: Define a ListBox items text.

    Try

    aaa.additem "Yes"
    The question is that the list items are already existing.
    I want to replace or modifiy them with new values.

    How to?

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [RESOLVED] Define a ListBox items text.

    How do you think this works?

    Code:
     msg = List1.ItemData(List1.ListIndex) & " "
      msg = msg & List1.List(List1.ListIndex)
    You can assign a value, as long as it's the right type
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured