Is there a way to filter combobox items (declared as single) to find which values are greater than an specific given value?
Printable View
Is there a way to filter combobox items (declared as single) to find which values are greater than an specific given value?
Er ... what does that actually mean?
Why not simply filter the data source and add the filtered items to the ComboBox ?
here's an example using a NumericUpDown control + a ComboBox:
Code:Public Class Form1
Dim items() As Single = Enumerable.Range(1, 10).Select(Function(x) CSng(x)).ToArray
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.AddRange(Array.ConvertAll(items, Function(f) CObj(f)))
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
ComboBox1.Items.Clear()
ComboBox1.Items.AddRange(Array.ConvertAll(items.Where(Function(f) f >= NumericUpDown1.Value).ToArray, Function(f) CObj(f)))
End Sub
End Class
A problem is similar to this thread where you helped. Now combobox take a function of datagridtable.
I find code which find specific value and modified to my problem but it only find value, not remove lowest values. Maybe it can be modified to works, or you have some other idea?
Here is a code:
Code:Public Class Form1
Private bsData As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tbl As New DataTable()
tbl.Columns.Add("ID", GetType(Int32))
tbl.Columns.Add("Number")
tbl.LoadDataRow(New Object() {1, 1}, True)
tbl.LoadDataRow(New Object() {2, 2}, True)
tbl.LoadDataRow(New Object() {3, 3}, True)
tbl.LoadDataRow(New Object() {4, 4}, True)
ComboBox1.DisplayMember = "Number"
ComboBox1.ValueMember = "ID"
bsData.DataSource = tbl
ComboBox1.DataSource = bsData
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Number As Single = TextBox1.Text
Dim Position = bsData.Find("Number", Number)
If Position <> -1 Then
bsData.Position = Position
Else
MessageBox.Show("'" & Number & "' was not located.")
End If
End Sub
End Class
Paul just provided an example. Posted same time you did.