How to maintain datagridview checkbox column checkstate when filtering
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: How to maintain datagridview checkbox column checkstate when filtering

  1. #1
    Join Date
    Oct 2017

    How to maintain datagridview checkbox column checkstate when filtering

    I have a dgvw.It loads data from an sql database.Now, i added a checkbox column to the dgvw.My winform also has a textbox that is used to search in/filter the datagridview. Here is my code:

    Private Sub Contact_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Private Sub filterdata(valuetosearch As String)
            Dim cmd As New SqlCommand("Select * from Contacts where CONCAT([Unique id],Prefix,[First name],[Last name],Gender,Title,Company,Phone,Mobile,Fax,[],[],Reference,Address,[Address 2],Country,City,Zip,Facebook,GooglePlus,Instagram,Twitter,Website,Salary,Currency,[Group],[Id/Status],Note,[Added by]) like '%" & valuetosearch & "%' ", con)
            Dim reader As SqlDataReader = cmd.ExecuteReader
            Dim dt As New DataTable
            userdatagrid.AutoGenerateColumns = True
            userdatagrid.DataSource = dt
        End Sub
        Private Sub searcgcon_TextChanged(sender As Object, e As EventArgs) Handles searcgcon.TextChanged
            If searcgcon.Text = "" Then
                entrylabel.Text = "There are/is " & userdatagrid.Rows.Count & " contact entries"
                entrylabel.Text = "There are/is " & userdatagrid.Rows.Count & " contact entries that contain your query :" & searcgcon.Text
            End If
        End Sub
    The problem with this code is, suppose i have checked a row's checkbox then i try to type something in the textbox/filter using the textbox.But as soon as i start typing the checkbox that was checked earlier becomes unchecked.I know i am wrong some where.I got this code from youtube and stackoverflow.So please help me..How do i maintain the checkstate while filtering ?
    Last edited by 2kaud; October 28th, 2017 at 10:50 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

On-Demand Webinars (sponsored)