Evening All
I'm having a headache with a dataGridview!
I have a blank datagridview and I autogenratecolumns set to true.
My dataset is 3 columns, 2 text columns and the 3rd returns either True or False.
My code for populating the dataGridView is below....what I need is for column 2, headed Monthly, to be a checkbox column, but I cannot work out how to do this....HELP!!
Thanks
Steve
I'm having a headache with a dataGridview!
I have a blank datagridview and I autogenratecolumns set to true.
My dataset is 3 columns, 2 text columns and the 3rd returns either True or False.
My code for populating the dataGridView is below....what I need is for column 2, headed Monthly, to be a checkbox column, but I cannot work out how to do this....HELP!!
Code:
Dim SQLSelect As New System.Text.StringBuilder
SQLSelect.Append("Select [Cust Ref], [Cust Delivery name], case when [Monthly ID] > 0 then 'True' Else 'False' End ")
SQLSelect.Append("From customers ")
SQLSelect.Append("Left Join Monthly On [Monthly Ref] = [Cust Ref] ")
SQLSelect.Append("where [Cust Ref] <> '' ")
SQLSelect.Append("Order By [Cust Ref]")
' Load Monthly Accounts
dgvMonthlyAccounts.Columns.Clear()
dgvMonthlyAccounts.DefaultCellStyle.ForeColor = Color.Black
Try
dgvMonthlyAccounts.AutoGenerateColumns = True
Using con As New SqlConnection(Main.DWDataConstr)
Using cmd As New SqlCommand(SQLSelect.ToString)
Using sda As New SqlDataAdapter()
sda.SelectCommand = cmd
cmd.Connection = con
con.Open()
Using ds As New DataSet
sda.Fill(ds)
dgvMonthlyAccounts.DataSource = ds.Tables(0)
End Using
End Using
End Using
End Using
dgvMonthlyAccounts.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
dgvMonthlyAccounts.BorderStyle = BorderStyle.Fixed3D
dgvMonthlyAccounts.RowHeadersVisible = False
' Customer Reference
dgvMonthlyAccounts.Columns(0).Width = 80
dgvMonthlyAccounts.Columns(0).HeaderCell.Value = "Customer Ref"
dgvMonthlyAccounts.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
dgvMonthlyAccounts.Columns(0).ReadOnly = True
' Customer Delivery Name
dgvMonthlyAccounts.Columns(1).Width = 250
dgvMonthlyAccounts.Columns(1).HeaderCell.Value = "Customer Name"
dgvMonthlyAccounts.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
dgvMonthlyAccounts.Columns(1).ReadOnly = True
' Monthly
dgvMonthlyAccounts.Columns(2).Width = 55
dgvMonthlyAccounts.Columns(2).HeaderCell.Value = "Monthly"
dgvMonthlyAccounts.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
' Record Updated
Dim CheckUpdated As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn With {
.HeaderText = "Monthly",
.Width = 55
}
dgvMonthlyAccounts.Columns.Add(CheckUpdated)
dgvMonthlyAccounts.Columns(3).Visible = False
Catch SQLEx_ As SqlException
MessageBox.Show("Unable to load Delivery Notes, contact Knibbs Support", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
dgvMonthlyAccounts.RowsDefaultCellStyle.BackColor = Color.LightBlue
dgvMonthlyAccounts.AlternatingRowsDefaultCellStyle.BackColor = Color.Silver
dgvMonthlyAccounts.AllowUserToAddRows = False
Thanks
Steve