anyway to add/shorten the string, substring doesn't work.
Use the Math.Round() method to shorten a "string" (really a number value as far as I can tell, but after rounding you can parse or cast it to a string which gets appended to the textbox afterwards.
I am confused on your question about matching positions and trying to match the position itself with some variable you have visible inside a listbox control though...
One idea is to populate your Listbox so that the long format is display with the short format stored but not shown by using a DataTable as the DataSource to a BindingSource which is the DataSource for the Listbox. When you need to locate a item i.e. 3.25 use the BindingSource Find method to set the Position in the ListBox
Code:
Public Class frmDemo1
WithEvents bsSomeValues As New BindingSource
Private Sub frmDemo1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim SomeValues As String() = _
{ _
"1.010000", _
"3.254367", _
"4.000000" _
}
Dim dtValues As New DataTable()
dtValues.Columns.Add("Display", GetType(String))
dtValues.Columns.Add("Value", GetType(String))
For Each item In SomeValues
dtValues.Rows.Add(item, CDec(item).ToString("f2"))
ListBox2.Items.Add(CDec(item).ToString("f2"))
Next
bsSomeValues.DataSource = dtValues
ListBox1.DisplayMember = "Display"
ListBox1.ValueMember = "Value"
ListBox1.DataSource = bsSomeValues
ListBox2.SelectedIndex = 1
End Sub
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdTest1.Click
ChangePosition()
End Sub
Private Sub ListBox2_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDoubleClick
ChangePosition()
End Sub
Private Sub ChangePosition()
Dim Postion = bsSomeValues.Find("Value", ListBox2.Text)
If Postion <> -1 Then
bsSomeValues.Position = Postion
End If
End Sub
End Class
This example finds a match in ListBox1 each time the position changes in ListBox2 (seebsData).
Code:
Public Class frmDemo1
WithEvents bsSomeValues As New BindingSource
WithEvents bsData As New BindingSource
Private Sub frmDemo1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ListValues As New List(Of String)
Dim SomeValues As String() = _
{ _
"1.010000", _
"3.254367", _
"4.000000" _
}
Dim dtValues As New DataTable()
dtValues.Columns.Add("Display", GetType(String))
dtValues.Columns.Add("Value", GetType(String))
For Each item In SomeValues
dtValues.Rows.Add(item, CDec(item).ToString("f2"))
ListValues.Add(CDec(item).ToString("f2"))
Next
bsSomeValues.DataSource = dtValues
ListBox1.DisplayMember = "Display"
ListBox1.ValueMember = "Value"
ListBox1.DataSource = bsSomeValues
bsData.DataSource = ListValues
ListBox2.DataSource = bsData
ActiveControl = ListBox2
End Sub
Private Sub bsData_PositionChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles bsData.PositionChanged
Dim Postion = bsSomeValues.Find("Value", CStr(bsData.Current))
If Postion <> -1 Then
bsSomeValues.Position = Postion
End If
End Sub
End Class
And i made a new program and added my own items to a listbox and converted them both to integeres and it didnt work, can anybody think of a solution? :S
also dont think im a n00b, i attached a screenshot of a previous proggy i worked on lol