Link to home
Start Free TrialLog in
Avatar of gwosgood
gwosgoodFlag for United States of America

asked on

Define CellType property for DataGridVewColumn member

Greetings Experts,

I have a DataGrid within my application that is loaded through a user-defined DataTable.  In addition to the fields that are called from the dataTable, I also need to define and add an additional column in the DataGrid, called "LapseDays".

The follow error occurs when I try to insert colLapseDays into the DataGrid:

"Column cannot be added because its CellType property is null."

Ive tried several different ways to define the default CellType property for this column, however it keeps saying that the property is read-only.  Any suggestions on how to fix this error so that I can move on with my program?

Any help is appreciated, thank you for your time.
strQueryString = "Select InvoiceNo,InvoiceAmt,InvoiceDate,MoneyAmt,RemitDate,ExceptionCode,OrderNo,CheckNo" & _
                            " FROM ARCurrent WHERE CustNmb = '" & strCustNmb & "' AND Terr = '" & strTerr & "' AND Div = '" & strDiv & "'"
 
            Me.Cursor = Cursors.WaitCursor
            Dim myTable As New DataTable
            Dim cmdFillARCurrent As New SqlDataAdapter(strQueryString, FPARconn)
            cmdFillARCurrent.Fill(myTable)
            dgvARCurrent.DataSource = myTable
 
            Dim colLapseDays As New DataGridViewColumn
            colLapseDays.HeaderText = "LapseDays"
            colLapseDays.Width = 50
 
            'adjust DataGrid columns
            dgvARCurrent.Columns.Item("InvoiceNo").Width = 60
            dgvARCurrent.Columns.Item("InvoiceAmt").Width = 75
            dgvARCurrent.Columns.Insert(6, colLapseDays)
            dgvARCurrent.Columns.Item("LapseDays").Width = 50
            Me.Cursor = Cursors.Default

Open in new window

Avatar of David L. Hansen
David L. Hansen
Flag of United States of America image

Do you just want the new column to be blank when it opens in the datagrid?
You can do this:

dgvARCurrent.Columns.Add()
ASKER CERTIFIED SOLUTION
Avatar of David L. Hansen
David L. Hansen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gwosgood

ASKER

Sorry for the delayed response, but I decided to go at the problem another way.  Instead of databinding the grid to my db, I just created my own columns, bound a dataTable to my SQL squery and then added the table to the grid.  This method allowed me to insert columns into my grid that were not fields within the dataTable.

I do appreciate your help though, and will reward your answer with points.
I almost always attach to a datatable too.