-
Feb 20th, 2013, 05:11 PM
#1
Thread Starter
Member
Filter Combobox items
Is there a way to filter combobox items (declared as single) to find which values are greater than an specific given value?
-
Feb 20th, 2013, 05:24 PM
#2
Re: Filter Combobox items
Er ... what does that actually mean?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Feb 20th, 2013, 05:30 PM
#3
Re: Filter Combobox items
Why not simply filter the data source and add the filtered items to the ComboBox ?
-
Feb 20th, 2013, 05:38 PM
#4
Re: Filter Combobox items
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 20th, 2013, 05:39 PM
#5
Thread Starter
Member
Re: Filter Combobox items
Originally Posted by dunfiddlin
Er ... what does that actually mean?
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
-
Feb 20th, 2013, 07:31 PM
#6
Re: Filter Combobox items
Paul just provided an example. Posted same time you did.
-
Feb 20th, 2013, 08:59 PM
#7
Thread Starter
Member
Re: Filter Combobox items
Originally Posted by Niya
Paul just provided an example. Posted same time you did.
Yes but I don't know to modify on my case.
Thanks anyway
I will try on the some other way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|