Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Can DataGridViewCheckBoxColumns stay checked when sorting?

$
0
0
I have a small project here where I'm reading data into a datatable from a .csv file and binding a DataGridView control to that table. The columns are autogenerated based on what was in the .csv file, and once the grid has been bound I'm adding a DataGridViewCheckBoxColumn to the front of the datagrid so the user can select rows based on their own criteria. The data from the rows they have selected are used to write out a text file which will be read into SAS to conditionally alter incoming data.

All of that works great; however, I end up with 30-40 columns, and they'll need to sort by one of those columns, check off boxes for the rows they're interested in, then sort by another column and repeat the process until they've selected enough rows.

The problem I'm having here is that when you sort a datagridview control, the checked boxes in the DataGridViewCheckBoxColumn get cleared instead of staying checked. How does one get the checkboxes to stay put? I've tried asking google, but I think I don't know how to ask my question. It seems so simple, why doesn't the checkbox become just another column in the record like any other field, containing a True or False value?

    Sub GetCsvData()
    
        Dim strInputPath As String = chrDrive & ":\L" & intLine & "MG" & strMG
        Dim strInputFileName As String = "L" & intLine & strMG & "sq.csv"
        Dim connString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
            & strInputPath & ";Extended Properties=""Text;HDR=No;FMT=Delimited"""
        Dim conn As New Odbc.OdbcConnection(connString)

        Dim da As New Odbc.OdbcDataAdapter("SELECT * FROM [" & strInputFileName & "]", conn)

        Dim dt As New DataTable
        da.Fill(dt)
        grdSumQual.DataSource = dt
      
  With grdSumQual
            .AutoGenerateColumns = True
            .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        End With

        Dim blnColumn As New DataGridViewCheckBoxColumn
        blnColumn.Name = "RateOut"
        blnColumn.HeaderText = "Rate Out"
        blnColumn.Frozen = True
        grdSumQual.Columns.Insert(0, blnColumn)

    End Sub


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>