Solved

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

Posted on 2003-11-10
6
772 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now