Hello, D.I.C heads.
I'm writing an application; I have an Advanced Tree control and a ListBox control. When I populate the ListBox programmatically, using a function that returns a ListBoxItem, it adds the field fine, but displaying incorrectly; it doesn't just add say "My item," it adds "ListViewItem: {My item}"
When I add the item using just a string, it adds fine but I need to use the return function to set the tag data and such, but when I use that function, it adds the above which is really annoying.
Is there something I'm doing wrong, or..?
Thanks, any help appreciated.
~huzi
ListBox Control proving difficult.
Page 1 of 19 Replies - 330 Views - Last Post: 07 May 2012 - 01:30 PM
Replies To: ListBox Control proving difficult.
#2
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 11:25 AM
Moving help question out of 'advanced topics'...
#3
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 11:43 AM
#4
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:05 PM
Show us the code you are using, as we ain't sitting next to you at your computer.
#5
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:09 PM
Without knowing how your adding the ListItems, we wont be able to instruct you on the correct or logical approach for this.
Although it seems like you have not set the Key and Value components of the ListBox from what it sounds like.
Although it seems like you have not set the Key and Value components of the ListBox from what it sounds like.
#6
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:24 PM
AdamSpeight2008, on 07 May 2012 - 08:05 PM, said:
Show us the code you are using, as we ain't sitting next to you at your computer.
Here's my function used to return my ListBoxItem:
Private Function GetItem(tag As FATXFileEntry) As ListViewItem
Dim x As New ListViewItem()
With x
.Name = tag.Name
.Text = tag.Name
.Tag = tag
End With
Return x
End Function
Furthermore, here's how I'm implementing my function:
lbFiles.Items.Clear()
For Each y As MY_OBJECT In x.Files
status = "Processing files..."
Dim Item As ListViewItem = GetItem(y)
lbFiles.Items.Add(Item)
Application.DoEvents()
Next
Thanks for your replies and willingness to help, it's appreciated.
~huzi
#7
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:29 PM
Try overriding ToString() for objects you add. Make it return whatever you want to see as name.
No code needed for this
No code needed for this
This post has been edited by Nerfpl: 07 May 2012 - 12:57 PM
#8
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:31 PM
#9
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 12:47 PM
I posted this at same time as you posted the code. Are you using ListBox or ListView?
ListBox takes object,
ListViewItem is for ListView.
ListBox will run ToString() on object to display its name.
ListView have ListViewItems with name etc, and optional tag for object link etc
/Btw typo. I meant 'overriding' instead of 'overloading'; for object meant for class of your object
example of what i meant
ListBox takes object,
ListViewItem is for ListView.
ListBox will run ToString() on object to display its name.
ListView have ListViewItems with name etc, and optional tag for object link etc
/Btw typo. I meant 'overriding' instead of 'overloading'; for object meant for class of your object
example of what i meant
listbox ' some ListBox Public Class ClassX Public Name As String = "my name" End Class listbox.Items.Add(new ClassX()) ' will display "ClassX" because that's the Object.ToString(); ' But Public Class ClassX Public Name As String = "my name" Public Overrides Function ToString() As String Return Me.Name End Function End Class listbox.Items.Add(new ClassX()) ' will now display "my name", and it will also update once name changes and list refreshes.
This post has been edited by Nerfpl: 07 May 2012 - 01:41 PM
#10
Re: ListBox Control proving difficult.
Posted 07 May 2012 - 01:30 PM
Nerfpl, on 07 May 2012 - 08:47 PM, said:
I posted this at same time as you posted the code. Are you using ListBox or ListView?
ListBox takes object,
ListViewItem is for ListView.
ListBox will run ToString() on object to display its name.
ListView have ListViewItems with name etc, and optional tag for object link etc
/Btw typo. I meant 'overriding' instead of 'overloading'; for object meant for class of your object
ListBox takes object,
ListViewItem is for ListView.
ListBox will run ToString() on object to display its name.
ListView have ListViewItems with name etc, and optional tag for object link etc
/Btw typo. I meant 'overriding' instead of 'overloading'; for object meant for class of your object
Thank you! I was using a ListBox when I should have been using a ListView.
Thanks again, greatly appreciated.
~huzi
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote









|