Results 1 to 7 of 7

Thread: Filter Combobox items

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    49

    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?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,599

    Re: Filter Combobox items

    Why not simply filter the data source and add the filtered items to the ComboBox ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    49

    Re: Filter Combobox items

    Quote Originally Posted by dunfiddlin View Post
    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

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,599

    Re: Filter Combobox items

    Paul just provided an example. Posted same time you did.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    49

    Re: Filter Combobox items

    Quote Originally Posted by Niya View Post
    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
  •  



Click Here to Expand Forum to Full Width