marcuthh marcuthh - 5 months ago 9
Vb.net Question

Visual Basic - DropDown text not altered to reflect value

I am working in

VB
and have an event that is supposed to update a number of values in a
DropDown
, and update the text accordingly:

For i As Integer = 0 To (prices.Items.Count - 1)
If prices.Items(i).Text.Contains("£") Then
Dim dConvertedValue = getTextAsDouble(prices.Items(i).Value) / dConversionRate
prices.Items(i).Value = dConvertedValue.ToString()

'should update displayable text here, but no change
prices.Items(i).Text = (Math.Floor(dConvertedValue).ToString("N") & "$")
End If
Next


This works fine in theory, and I have stepped-through and can see that the values are changing as expected. However, the Dropdown does not update at any point.

I'm very new to VB, so it could be something as simple as a syntax error. Does anybody know why this might be?

Mark

Answer

Try using this I have used your exact code but changed the loop to 'For each'

For each Item as ListItem in prices.items
    If Item.Text.Contains("£") Then
        Dim dConvertedValue = (getTextAsDouble(Item.Value) / dConversionRate)
        Items.Value = dConvertedValue.ToString()
        Items.Text = (Math.Floor(dConvertedValue).ToString("N") & " sq m")
    End If
Next