Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Setting desired column in datagridview to combobox,checkbox

Setting desired column in datagridview to combobox,checkbox

Setting desired column in datagridview to combobox,checkbox


I have a Datagridview which is populated from a sql query. The order of the columns and binding of the grid are handled at runtime. Problem is I cannot find a way to assign the combobox and checkbox to the columns I desire. In the example below column (1) and the last column share the same header names. I'm trying to have the last Column ( filled with a combobox ) show in column (1). All examples I've come across, always show comboboxes and checkboxes as the end columns. As shown in the example I can achieve this. But I can not find any examples with code to show how to populate the desired columns with the comboboxes or checkboxes.

Thank you for any help

Imports System.Data.OleDb
Public Class frm_Checkbook

Dim dbAdapter As OleDb.OleDbDataAdapter
Dim dbDataSet As New DataSet
Dim dbDataTable As New DataTable
Dim strSQL As String

Private Sub frm_Checkbook_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call datagridShow()
End Sub

Private Sub datagridShow()

strSQL = "Select Date,Transaction,Chkno,Payee,Category,Memo,Amount,Balance,Clear FROM Banking"

Using dbAdapter As New OleDb.OleDbDataAdapter(strSQL, gbl_DstConnect)
Using dbDataTable As New DataTable()

DataGridView1.AutoGenerateColumns = False
DataGridView1.Size = New Size(960, 574) 'New Size(882, 574)
DataGridView1.RowTemplate.Height = 22
DataGridView1.ColumnCount = 8

DataGridView1.Columns(0).Width = 70
DataGridView1.Columns(0).Name = "Date"
DataGridView1.Columns(0).HeaderText = " Date"
DataGridView1.Columns(0).DataPropertyName = "Date"

DataGridView1.Columns(1).Width = 78
DataGridView1.Columns(1).Name = "Transaction"
DataGridView1.Columns(1).HeaderText = "Transaction"
DataGridView1.Columns(1).DataPropertyName = "Transaction"

DataGridView1.Columns(2).Width = 50
DataGridView1.Columns(2).Name = "Chkno"
DataGridView1.Columns(2).HeaderText = "Chkno"
DataGridView1.Columns(2).DataPropertyName = "Chkno"

DataGridView1.Columns(3).Width = 200
DataGridView1.Columns(3).Name = "Payee"
DataGridView1.Columns(3).HeaderText = " Payee"
DataGridView1.Columns(3).DataPropertyName = "Payee"

DataGridView1.Columns(4).Width = 100
DataGridView1.Columns(4).Name = "Category"
DataGridView1.Columns(4).HeaderText = " Category"
DataGridView1.Columns(4).DataPropertyName = "Category"

DataGridView1.Columns(5).Width = 120
DataGridView1.Columns(5).Name = "Memo"
DataGridView1.Columns(5).HeaderText = " Memo"
DataGridView1.Columns(5).DataPropertyName = "Memo"

DataGridView1.Columns(6).Width = 80
DataGridView1.Columns(6).DefaultCellStyle.Format = String.Format("c")
DataGridView1.Columns(6).Name = "Amount"
DataGridView1.Columns(6).HeaderText = " Amount"
DataGridView1.Columns(6).DataPropertyName = "Amount"

DataGridView1.Columns(7).Width = 90
DataGridView1.Columns(7).DefaultCellStyle.Format = String.Format("c")
DataGridView1.Columns(7).Name = "Balance"
DataGridView1.Columns(7).HeaderText = " Balance"
DataGridView1.Columns(7).DataPropertyName = "Balance"

Dim Cleared As New DataGridViewCheckBoxColumn()
Cleared.HeaderText = "Cleared"
Cleared.Name = "Cleared"
Cleared.Width = 50
Cleared.ReadOnly = True
DirectCast(DataGridView1.Columns("Cleared"), DataGridViewCheckBoxColumn).DataPropertyName = "Clear"

Dim Type As New DataGridViewComboBoxColumn()
Type.HeaderText = "Transactions"
Type.Name = "Type"
Type.Width = 78
Type.MaxDropDownItems = 4
Type.Items.Add("Misc Additions")
Type.Items.Add("Misc Charges")
Type.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
DirectCast(DataGridView1.Columns("Type"), DataGridViewComboBoxColumn).DataPropertyName = "Transaction"

DataGridView1.DataSource = dbDataTable
DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.Rows.Count - 1 'Scroll to end of records

'Disable column sort
For i = 0 To DataGridView1.Columns.Count - 1
DataGridView1.Columns.Item(i).SortMode = DataGridViewColumnSortMode.Programmatic
Next i

End Using
End Using


End Sub

End Class

RE: Setting desired column in datagridview to combobox,checkbox

Instead of using the Add method, like this:


use the Insert method, which allows you to specify the index of the column:

DataGridView1.Columns.Insert(1, Type)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Setting desired column in datagridview to combobox,checkbox

Excellent, Sorry for not getting back earlier

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close