Datagrid Checkbox Column

M

Mike Fellows

im trying (unsucessfully) to add a checkbox column to my datagrid

i basically have a datagrid that im populating from a dataset

Me.DataGrid1.DataSource = ds.Tables(0)

the datagrid then has 5 columns in it but i need to add a sixth column
which will be my checkbox column - any help or pointers with this
would be great

Thanks

Mike
 
L

Lars Netzel

You need to add a TableStyle to the Grid, including the Columns you want.
Make the last Column you add to the style a DataGridCheckBoxColumn

/Lars
 
M

Mike Fellows

Ok,

ive added my TableStyle (i think)

Dim ts As New DataGridTableStyle
ts.MappingName = "Table"
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)

but now i still have no idea how to add the extra column

Thanks

Mike
 
L

Lars Netzel

Here: You create a Column and add to the style that you then add to the Grid
(like you did)

Dim ts As New DataGridTableStyle
ts.MappingName = "Table"

Dim txtID As New DataGridTextBoxColumn

txtID.MappingName = "ID column name from database"

txtID.HeaderText = "ID"

txtID.Width = 50

ts.GridColumnStyles.Add(txtID)

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)


/Lars
 
M

Mike Fellows

thanks, well that sort of helped as i can now manuipulate my other columns
easier but im still no closer to adding a
check box

heres my current code:

Dim ts As New DataGridTableStyle
ts.MappingName = "Table"

Dim txtID As New DataGridTextBoxColumn
txtID.MappingName = "ID"
txtID.HeaderText = "ID"
txtID.Width = 50
ts.GridColumnStyles.Add(txtID)

Dim txtID1 As New DataGridTextBoxColumn
txtID1.MappingName = "Postcode"
txtID1.HeaderText = "Postcode"
txtID1.Width = 80
ts.GridColumnStyles.Add(txtID1)

Dim txtID2 As New DataGridTextBoxColumn
txtID2.MappingName = "DistributionVolume"
txtID2.HeaderText = "Distribution Volume"
txtID2.Width = 80
ts.GridColumnStyles.Add(txtID2)

Dim txtID3 As New DataGridTextBoxColumn
txtID3.MappingName = "Distributor"
txtID3.HeaderText = "Distributor"
txtID3.Width = 80
ts.GridColumnStyles.Add(txtID3)

Dim txtID4 As New DataGridTextBoxColumn
txtID4.MappingName = "Frequency"
txtID4.HeaderText = "Frequency"
txtID4.Width = 80
ts.GridColumnStyles.Add(txtID4)

Dim txtID5 As New DataGridTextBoxColumn
txtID5.MappingName = "WeekCommencing"
txtID5.HeaderText = "Week Commencing"
txtID5.Width = 80
ts.GridColumnStyles.Add(txtID5)

Dim txtID6 As New DataGridTextBoxColumn
txtID6.MappingName = "Active"
txtID6.HeaderText = "Active"
txtID6.Width = 80
ts.GridColumnStyles.Add(txtID6)

Dim txtID7 As New DataGridTextBoxColumn
txtID7.MappingName = ""
txtID7.HeaderText = "CHECKBOX HERE PLEASE"
txtID7.Width = 120
ts.GridColumnStyles.Add(txtID7)

DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Me.DataGrid1.DataSource = ds.Tables(0)


i dont seem to be able to add the DataGridCheckBoxColumn you originally
mentioned
and also this column should not be mapped to anything

Thanks

Mike
 
K

Ken Tucker [MVP]

Hi,

Add a new column to your dataset. Add a datagridboolcolumn to your
tablestyle.

Dim dc As New DataColumn("MyBoolColumn", GetType(Boolean))
dc.DefaultValue = False
ds.Tables("Table").Columns.Add(dc)

Dim txtID7 As New DataGridBoolColumn
txtID7.MappingName = "MyBoolColumn"
txtID7.HeaderText = "CHECKBOX HERE PLEASE"
txtID7.Width = 120
ts.GridColumnStyles.Add(txtID7)

Ken
------------------
 
M

Mike Fellows

Thanks Ken

works a treat

Mike

Ken Tucker said:
Hi,

Add a new column to your dataset. Add a datagridboolcolumn to your
tablestyle.

Dim dc As New DataColumn("MyBoolColumn", GetType(Boolean))
dc.DefaultValue = False
ds.Tables("Table").Columns.Add(dc)

Dim txtID7 As New DataGridBoolColumn
txtID7.MappingName = "MyBoolColumn"
txtID7.HeaderText = "CHECKBOX HERE PLEASE"
txtID7.Width = 120
ts.GridColumnStyles.Add(txtID7)

Ken
 
A

Ali baba the 40th

Just now I ask same question related with this caption.
I add a checkbox column myself to the datagrid
at the run time if you click ones it's states turn to lock mode if you clik
seceond time it turn to un checked mode
how can I arrange this stiuation ?
 
M

Mike Fellows

Ken,

im now looking around the web to be able to do a combobox column too
but everything says i should be able to access DataGridComboBoxColumn

this does not exist as far as i can tell (this was the same as i was told
earlier for the DataGridCheckBoxColumn which didnt exist either)

im using .net 2003 with framwork 1.1 so i should be up to date

why dont these objects exist?

and how do i transform a DataGridTextBoxColumn which i have into a
combobox?

this is such a pain in the arse (roll on whigby with its new datagrids)

Mike
 
L

Lars Netzel

There's no default class for this, you need to download a class from the
site provided in the pther message. I needed this for sure and I spent a few
hours to get it to work, but that class is not very nice, it lacks several
handlers for key events and doesnt raise events either, don't asume it'll be
as working with a normal ComboBOx. I had to modify the class I downloaded
pretty much but that's custumized a lot with the rest of my form and the
grid it's in so I dont' think it'll help you very much lookng at it.

But I got it workning. So I'll try to answer questions

/Lars



Mike Fellows said:
Ken,

im now looking around the web to be able to do a combobox column too
but everything says i should be able to access DataGridComboBoxColumn

this does not exist as far as i can tell (this was the same as i was told
earlier for the DataGridCheckBoxColumn which didnt exist either)

im using .net 2003 with framwork 1.1 so i should be up to date

why dont these objects exist?

and how do i transform a DataGridTextBoxColumn which i have into a
combobox?

this is such a pain in the arse (roll on whigby with its new datagrids)

Mike





Ken Tucker said:
Hi,

That's it default behavior.
http://msdn.microsoft.com/library/d...mWindowsFormsDataGridBoolColumnClassTopic.asp
 
G

Guest

Hi..

I was tryin to populate data into a datagrid on my "Pocket PC 2003"
applicaiton (using emulator). Since I'm new to Pocket PC, I tried the way i
was using in ASP.NET. But, got error message:

Following are the code I tried to populate data from SQL CE table to
"DataGrid". But it doesn't work. Apprecaite if you could show any sample code
or URsL showing declaration and using of "DataReader, DataSet, DataAdaptor
etcc in a PocketPC applicaiton.

Dim cn1 As New System.Data.SqlServerCe.SqlCeConnection("Data Source=\my
documents\NWIND_CE.sdf;password=ahd")

Dim cmd1 As New SqlCeCommand
Dim dr1 As SqlCeDataReader
Try
cn1.Open()
cmd1.CommandText = "select
acct_number,acct_name,acct_ibu,acct_group from CMF"
cmd1.Connection = cn1
dr1 = cmd1.ExecuteReader

Me.DataGrid1.DataSource = dr1
dr1.Close()
cn1.Close()
Catch Err As SqlCeException
showErrors(Err)
Finally
cn1 = Nothing
End Try

Many thanks in advance...

Regards,

Ahmed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top