Solved

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

Posted on 2003-11-10
6
782 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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