Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-10
6
Medium Priority
?
809 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

877 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