Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Check box getting unchecked while sorting column in datagridview

Check box getting unchecked while sorting column in datagridview

Scheduled Pinned Locked Moved Visual Basic
algorithmssecurityhelpquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hisuman100
    wrote on last edited by
    #1

    Check box column getting unchecked when I am sorting column in datagridview. Can any one help me? Regds. Suman Imports System Imports System.Data.SqlClient Public Class Form1 Dim str As String Dim con As SqlConnection Dim da As SqlDataAdapter Dim ds As New DataSet Dim dt As DataTable Dim dv As DataView Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load str = "Integrated Security=SSPI; User Id=sa;Initial Catalog=MAS08; Data Source = suman" con = New SqlConnection(str) con.Open() str = "select * from unitmaster" da = New SqlDataAdapter(str, con) da.Fill(ds, "unitmaster") dt = ds.Tables(0) dv = New DataView(dt) Dim colCheckbox As New DataGridViewCheckBoxColumn() ' Size the column width so it is wide enough to display the header colCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader colCheckbox.ThreeState = False colCheckbox.TrueValue = 1 colCheckbox.FalseValue = 0 colCheckbox.IndeterminateValue = System.DBNull.Value colCheckbox.DataPropertyName = "Checkbox" colCheckbox.HeaderText = "Checkbox" colCheckbox.Name = "Checkbox" 'colCheckbox.ReadOnly = True dgv.Columns.Add(colCheckbox) dgv.DataSource = dv End Sub End Class

    B 1 Reply Last reply
    0
    • H hisuman100

      Check box column getting unchecked when I am sorting column in datagridview. Can any one help me? Regds. Suman Imports System Imports System.Data.SqlClient Public Class Form1 Dim str As String Dim con As SqlConnection Dim da As SqlDataAdapter Dim ds As New DataSet Dim dt As DataTable Dim dv As DataView Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load str = "Integrated Security=SSPI; User Id=sa;Initial Catalog=MAS08; Data Source = suman" con = New SqlConnection(str) con.Open() str = "select * from unitmaster" da = New SqlDataAdapter(str, con) da.Fill(ds, "unitmaster") dt = ds.Tables(0) dv = New DataView(dt) Dim colCheckbox As New DataGridViewCheckBoxColumn() ' Size the column width so it is wide enough to display the header colCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader colCheckbox.ThreeState = False colCheckbox.TrueValue = 1 colCheckbox.FalseValue = 0 colCheckbox.IndeterminateValue = System.DBNull.Value colCheckbox.DataPropertyName = "Checkbox" colCheckbox.HeaderText = "Checkbox" colCheckbox.Name = "Checkbox" 'colCheckbox.ReadOnly = True dgv.Columns.Add(colCheckbox) dgv.DataSource = dv End Sub End Class

      B Offline
      B Offline
      BDEz Member 3919223
      wrote on last edited by
      #2

      So your checkbox works up to the point of when you are looking at the data in your datagrid and you manually sort the data, you lose your check mark that was placed in the check box? If that is the case, then you most likely will need to remove the functionality of your data grid (cant be manually sorted or resized etc.etc) and write your own sorting function that scans the check box's to see if they have a check first before you allow your datagrid to resort.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups