|
-
Jul 7th, 2009, 09:11 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] datagridview column formatting
hi guru's Im trying to format datagridview column to a checkbox as its column is assigned to msaccess YES/NO data type.
vb1 Code:
DataGridView.Columns(2).DefaultCellStyle.Format = "Bit"
AND
vb2 Code:
DataGridView.Columns(2).DefaultCellStyle.Format = "Boolean"
is there anyway to do this. thanks.
-
Jul 7th, 2009, 09:25 AM
#2
Re: datagridview column formatting
Use a DataGridViewCheckBoxColumn
-
Jul 8th, 2009, 01:27 AM
#3
Re: datagridview column formatting
If you simply populate a DataTable from your database and bind that to the grid then it will use a check box column automatically. Any particular reason you're not doing that?
-
Jul 8th, 2009, 07:31 AM
#4
Thread Starter
Fanatic Member
Re: datagridview column formatting
 Originally Posted by jmcilhinney
If you simply populate a DataTable from your database and bind that to the grid then it will use a check box column automatically. Any particular reason you're not doing that?
I agree unless there something wrong in the code.
Code:
With _grid
.DataSource = Nothing
.DataSource = dtDataGrid
'hide column 0
.Columns(0).Visible = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.Cursor = Cursors.Hand
If _readonly Then
.ReadOnly = True
.AllowUserToAddRows = False
End If
End With
Last edited by jlbantang; Jul 8th, 2009 at 07:34 AM.
-
Jul 8th, 2009, 07:41 AM
#5
PowerPoster
Re: datagridview column formatting
otherwise just create a checkboxcolumn and bind it to the appropriate column:
Code:
Dim checkboxcolumn As New DataGridViewCheckBoxColumn
checkboxcolumn.HeaderText = "Test"
checkboxcolumn.DataPropertyName = "TestColumn"
checkboxcolumn.DisplayIndex = 3
With dgvTest
.Columns.Add(checkboxcolumn)
end with
-
Jul 9th, 2009, 04:37 AM
#6
Thread Starter
Fanatic Member
Re: datagridview column formatting
Nitesh: the code work indeed as it ADD a column with checkbox format but it doesnt solve the issue. I just want the column to be formatted as checkbox.
i did it like this:
Code:
Dim checkboxcolumn As New DataGridViewCheckBoxColumn
borrowerloanDataGridView.Columns(2).DefaultCellStyle = checkboxcolumn
obviously it has convertion error
Last edited by jlbantang; Jul 9th, 2009 at 04:43 AM.
-
Jul 9th, 2009, 05:23 AM
#7
Re: datagridview column formatting
There's no such thing as "formatting a column as checkbox". If you want a column of check boxes then you use a DataGridViewCheckBoxColumn, plain and simple. You can't use some other type of column, e.g. a DataGridViewTextBoxColumn, and then somehow change its type to display check boxes. Each different type of column is designed to host a different type of control. If you want check boxes you use a DataGridViewCheckBoxColumn.
The DefaultCellStyle has absolutely nothing to do with this. The control hosted in the cells of a column is nothing to do with format.
There's also no reason for you to have any code for this. You should be adding the column in the designer. If you need to bind it to a column or property in the grid's DataSource then you need to set the column's DataPropertyName.
-
Jul 9th, 2009, 06:47 AM
#8
Thread Starter
Fanatic Member
Re: datagridview column formatting
Right, and i found out it was TOTALLY a WRONG column passed in sql-select.
OMG!!!
Thanks anyway.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|