Solved

VB .NET ListBox - ToString() called, but redraws with original values

Posted on 2003-11-10
6
763 Views
Last Modified: 2008-01-09
This should be easy, looks like I just need to call the function to force VB to update its internal values and repaint after that.  It is repainting the form however, but it is displaying the wrong values.  All the values are correct in the ListBox object, they are just showing up wrong.  Visual Basic does call the ToString function for the object, and it does return the correct value.  Any ideas what might be wrong?

I included the code for the areas in question.  Hope it helps.

Public Class HashedItem
    Protected m_Hash As Hashtable
    Protected m_Keys() As String
    Protected m_strDelimeter As String

    Public Function GetEnum() As System.Collections.IDictionaryEnumerator
        Return m_Hash.GetEnumerator
    End Function
    Public Sub New(ByVal strDisplay As String, ByVal strDelimeter As String)
        m_Hash = New Hashtable
        m_Keys = Split(strDisplay, ",")
        m_strDelimeter = strDelimeter
    End Sub

    Public Sub AddItem(ByVal strKey As String, ByVal strValue As Object)
        m_Hash.Add(strKey, strValue)
    End Sub
    Public Sub SetItem(ByVal strKey As String, ByVal strValue As Object)
        m_Hash(strKey) = strValue
    End Sub

    Public Function GetValue(ByVal strKey As String) As Object
        Return m_Hash(strKey)
    End Function

    Public Property Delimter()
        Get
            Return m_strDelimeter
        End Get
        Set(ByVal Value)

        End Set
    End Property

    Public Property Count()
        Get
            Return m_Hash.Count
        End Get
        Set(ByVal Value)

        End Set
    End Property
    Public Function GetString(ByVal strKey As String) As String

        Dim strString As String
        strString = CStr(m_Hash(strKey))
        Return strString
    End Function

    Overrides Function ToString() As String
        Dim i As Integer
        Dim str As String

        str = m_Hash(m_Keys(i))
        For i = 1 To UBound(m_Keys)
            str = str & m_strDelimeter & m_Hash(m_Keys(i))
        Next

        'ToString = str
        Return str
    End Function
End Class

Editing the items:

 Public Sub EditHasheditem(ByRef Control As Object)
        Dim i As Integer
        Dim e As System.Collections.IDictionaryEnumerator
        Dim Label As Label
        Dim TextBox As TextBox


        m_Controls = New ControlList
        Dim HashedItem As HashedItem

        HashedItem = Control.SelectedItem


        e = HashedItem.GetEnum
        e.MoveNext()

        Dim startHeight As Int16
        startHeight = 0
        Dim strLabel, strText As String

        For i = 0 To HashedItem.Count - 1
            strText = "txt" & e.Key
            strLabel = "lbl" & e.Key

            Label = New Label
            Label.Text = e.Key
            Label.Left = 15
            Label.Width = 100
            Label.Top = startHeight
            Label.Name = strLabel

            TextBox = New TextBox
            TextBox.Text = e.Value
            TextBox.Left = 120
            TextBox.Width = 100
            TextBox.Top = startHeight
            TextBox.Name = e.Key

            Controls.Add(TextBox)
            Controls.Add(Label)
            m_Controls.AddTail(TextBox)

            startHeight = startHeight + 25
            e.MoveNext()

        Next
        cmdCancel.Top = startHeight
        cmdUpdate.Top = startHeight

        Width = TextBox.Left + TextBox.Width + 10
        Height = startHeight + 50


        m_HashedItem = HashedItem
        m_ParentControl = Control
        m_iTargetIndex = Control.SelectedIndex


    End Sub


    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
        Dim i As Integer

        m_Controls.Start()
        m_Controls.NextNode()

        m_ParentControl.SelectedIndex = m_iTargetIndex
        For i = 0 To m_HashedItem.Count - 1
            m_ParentControl.SelectedItem.SetItem(m_Controls.Value.Name, m_Controls.Value.Text)
            m_Controls.NextNode()

        Next

        m_ParentControl.ResetText()  'trying them all
        m_ParentControl.UPdate() 'see if it works
        m_ParentControl.visible = True

        MsgBox(m_ParentControl.SelectedItem.ToString())

        '  = m_HashedItem
        Me.Close()
        Me.Dispose()

    End Sub
0
Comment
Question by:Discofish
6 Comments
 
LVL 4

Expert Comment

by:NetPointer
ID: 9717881
did not understood yr question :( what does it mean by showing wrong? u mean order? then try for sorting property of listbox...

NetPointer
0
 
LVL 2

Author Comment

by:Discofish
ID: 9718814
I mean, I have a list of points

1,5
2,5
6,0

and I update 1,5 to be 20,300.
The ItemData object gets 20,300.  The list still says 1,5.  The ToString() method of the object I used in the list is getting called.  VB is not drawing them on the list, however.
0
 
LVL 2

Author Comment

by:Discofish
ID: 9718824
I didn't mean ItemData...I was refering to "SelectedItem", which is what I am modifying.  But like I said, internally the listbox has the correct values after I call the code to update them.  They still contain the values from the time when I first inserted them in the list though.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Author Comment

by:Discofish
ID: 9790832
Problem solved.

I deleted the item, created a new item,
then added that item in the same index position.

I look at this as a hack, as it should be able to be done the way I was doing it (manipulating the values already in memory).  Since no one was able to help, I would like my points back. Thanks.

Discofish
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10256748
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 10314986
PAQed, with points refunded (200)

SpazMODic
EE Moderator
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now