VB.NET Tutorial : How to Fillter DataGridView using Multiple CheckBox

VB.Net tutorial for beginner : how to fillter datagridview using multiple Checkbox in vb.net, Values DataGridView will fillter bu CheckBox

VB.Net Tutorial - How we can fillter a DataGridView using Multiple CheckBox where data storing from a database (MySQL) database. In preiews Lessons, we have learn about how to filltering DataGridview from a textBox, read How to Filter DataGridView Using TextBox and MySQL Database and How to Search/Fillter Items in a ListBox.

Fillter DataGridView using Multiple CheckBox

in your visual studio, create new project and rename it with "FillterDataGridView" and at the form1.vb add one DataGridView, Two GroupBox, and five CheckBox, see images below :

How to Fillter DataGridView using Multiple CheckBox

Next, Add new Module, called "ModuleConnection.vb" for our connection to database using ODBC class, or you can crate using ADO.NET.

Source Code ModuleConnection.vb

Imports System.Data.Odbc ' we can use ODBC class to create a connection
Module ModuleConnections
    ' first you must have a database,
    ' and we will connect it using ODBC connection.
    ' i have a database (MySQL database) and has create ODBC connection
    Public connection As OdbcConnection
    Public Sub connect()
        Try
            connection = New OdbcConnection("DSN=k13new;MultipleActiveResultSets=True")
            If connection.State = ConnectionState.Closed Then
                ' open connection
                connection.Open()
            End If
        Catch ex As Exception
            MsgBox("Connection failed!")
        End Try
    End Sub
End Module

Source Code Fillter Data (Form1.vb)

Imports System.Data.Odbc
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' open connection
        connect()
        Dim da As New OdbcDataAdapter("SELECT * FROM siswa", connection)
        Dim ds As New DataSet ' we will use dataset
        da.Fill(ds, "siswa")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "siswa"
        da.Dispose()
        connection.Close()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim query As String = ""
        Dim query2 As String = ""
        Dim c1check As Boolean
        Dim c2check As Boolean

        Dim myList As New List(Of String)
        For Each cb As CheckBox In GroupBox1.Controls.OfType(Of CheckBox)
            ' we can know if checkbox in GroupBox1 is checked or not
            If cb.Checked Then
                c1check = True
                ' get the text of checkbox that checked by user
                myList.Add(cb.Text)
            End If
        Next

        ' now , add the same function to get value from groupbox 2
        Dim myList2 As New List(Of String)
        For Each cb2 As CheckBox In GroupBox2.Controls.OfType(Of CheckBox)
            ' we can know if checkbox in GroupBox2 is checked or not
            If cb2.Checked Then
                c2check = True
                ' get the text of checkbox that checked by user
                myList2.Add(cb2.Text)
            End If
        Next

        If c1check Then
            ' if checkbox in groupbox1 is checked, we will create this query to our database
            query = "SELECT * FROM siswa WHERE kelas='" & String.Join("' or kelas=" + "'", myList) + "'"
        End If
        If c2check Then
            ' if checkbox in groupbox2 is checked, we will create this query to our database
            query = "SELECT * FROM siswa WHERE jeniskelamin='" & String.Join("' or jeniskelamin=" + "'", myList2) + "'"
        End If
        If c1check And c2check Then
            ' if checkbox in GorupBox 1 and 2 is checked, we will create this query to our database
            query = "SELECT * FROM siswa WHERE (kelas='" & String.Join("' or kelas=" + "'", myList) + "') AND (jeniskelamin='" & String.Join("' or jeniskelamin=" + "'", myList2) + "')"

        End If

        ' open connection
        connect()
        Dim da As New OdbcDataAdapter(query, connection)
        Dim ds As New DataSet

        da.Fill(ds, "siswa")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "siswa"
        da.Dispose()
        connection.Close()
    End Sub
End Class

Video tutorial How to Fillter DataGridView using Multiple CheckBox



Download Project http://bit.ly/2ckFI2r

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: VB.NET Tutorial : How to Fillter DataGridView using Multiple CheckBox
VB.NET Tutorial : How to Fillter DataGridView using Multiple CheckBox
VB.Net tutorial for beginner : how to fillter datagridview using multiple Checkbox in vb.net, Values DataGridView will fillter bu CheckBox
https://4.bp.blogspot.com/-w3Hoj9eLir8/V9BLkbDYZnI/AAAAAAAACds/4yew31ZCWMsOppqpfnEAr2EO-CqlJc-_wCLcB/s320/vb-net-fillter-datagridview-checkbox.png
https://4.bp.blogspot.com/-w3Hoj9eLir8/V9BLkbDYZnI/AAAAAAAACds/4yew31ZCWMsOppqpfnEAr2EO-CqlJc-_wCLcB/s72-c/vb-net-fillter-datagridview-checkbox.png
KODE AJAIB
https://www.kodeajaib.com/2016/09/how-to-fillter-datagridview-using-checkbox.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/09/how-to-fillter-datagridview-using-checkbox.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy