checkbox greyed out in datagrid....

M

magmo

Hi


I have created a windows form that hold a datagrid, that datagrid gets
it values from a stored procedure. My problem is that I have added a
checkbox to the datagrid and applied some style to the datagrid. But
the checkbox is always greyed out. Why is that, and what am I doing
wrong?

Here's my code...

<code>

Sub BindData(ByVal OrderID As String)
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As New DataSet

Dim strConn As String
strConn = ("myconnstr")

myConnection = New SqlConnection(strConn)
myConnection.Open()
myCommand = New SqlCommand("p_PDFDetail", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add("@CartID", SqlDbType.NVarChar, 50).Value =
OrderID
myDataAdapter = New SqlDataAdapter(myCommand)
myDataAdapter.Fill(myDataSet, "tbl_Order")

Dim myDataTable As New DataView(myDataSet.Tables("tbl_Order"))
myDataSet.Tables("tbl_Order").Columns("InfileMap").ColumnMapping =
MappingType.Hidden

Dim ts1 As New DataGridTableStyle

ts1.MappingName = "tbl_Order"

ts1.AlternatingBackColor = Color.LightGray

Dim TextCol1 As New DataGridTextBoxColumn
Dim TextCol2 As New DataGridTextBoxColumn
Dim TextCol3 As New DataGridTextBoxColumn
Dim TextCol4 As New DataGridTextBoxColumn
Dim TextCol5 As New DataGridTextBoxColumn

TextCol1.MappingName = "CartID" 'from dataset table
TextCol1.HeaderText = "OrderID"
TextCol1.Width = 100

TextCol2.MappingName = "Quantity" 'from dataset table
TextCol2.HeaderText = "Qty"
TextCol2.Width = 50
TextCol2.Alignment = HorizontalAlignment.Center

TextCol3.MappingName = "ArtNr" 'from dataset table
TextCol3.HeaderText = "Article nr"
TextCol3.Width = 75

TextCol4.MappingName = "Description" 'from dataset table
TextCol4.HeaderText = "Product"
TextCol4.Width = 250

TextCol5.MappingName = "Country" 'from dataset table
TextCol5.HeaderText = "Language"
TextCol5.Width = 100

ts1.GridColumnStyles.Add(TextCol1)
ts1.GridColumnStyles.Add(TextCol2)
ts1.GridColumnStyles.Add(TextCol3)
ts1.GridColumnStyles.Add(TextCol4)
ts1.GridColumnStyles.Add(TextCol5)

MyDataGrid.DataSource = myDataSet
'MyDataGrid.AlternatingBackColor = Color.LightGray
MyDataGrid.TableStyles.Add(ts1)
MyDataGrid.ReadOnly = True

'STEP 4: Add the checkbox
Dim boolCol As New DataGridBoolColumn
With boolCol
.HeaderText = "Make PDF"
.MappingName = "ID"
.Width = 75
.TrueValue = True
.FalseValue = False
.ReadOnly = False
.Alignment = HorizontalAlignment.Center
.AllowNull = False
End With
ts1.GridColumnStyles.AddRange(New DataGridColumnStyle() {boolCol})

MyDataGrid.TableStyles.Add(ts1)

MyDataGrid.DataMember = "tbl_Order"
End Sub

</code>


Regards



Magnus
 
K

Ken Tucker [MVP]

Hi,

A grayed out checkbox means that is value is null or unknown. I
noticed that your datagridboolcolumn is bound to a field named ID. Is ID
a Boolean value? You might have to add a new Boolean column to your
dataset with its default value set to false.

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

magmo

Hi Ken

No the ID value is the primary key in the DB. The thing I want to
accomplish is....

I need a checkbox column in the datagrid so that I can select ine or
more records in the datagrid, and when I have done that, press a
button that iterate through the datagrid and get the marked
checkboxes ID.

I guess I have approach it wrong, can I add a Boolean column to the
dataset that is not mapped to a column in the database or should I do
it some over way to achive what I try to do here?


Regards


Magnus
 
G

Greg Burns

Take a look at
http://www.metabuilders.com/Tools/RowSelectorColumn.aspx

HTH,
Greg

magmo said:
Hi Ken

No the ID value is the primary key in the DB. The thing I want to
accomplish is....

I need a checkbox column in the datagrid so that I can select ine or
more records in the datagrid, and when I have done that, press a
button that iterate through the datagrid and get the marked
checkboxes ID.

I guess I have approach it wrong, can I add a Boolean column to the
dataset that is not mapped to a column in the database or should I do
it some over way to achive what I try to do here?


Regards


Magnus
 

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