473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

checkbox greyed out in datagrid....

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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
4 4408
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
------------

"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> wrote in message
news:40**********@Usenet.com:
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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
HYPERLINK "http://www.usenet.com"http://www.usenet.com


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.1.2 - Release Date: 6/7/2004
Nov 20 '05 #2
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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #3
Take a look at
http://www.metabuilders.com/Tools/Ro...torColumn.aspx

HTH,
Greg

"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #4
Almost forgot, here is some VB.NET example code that uses it...
http://www.datagridgirl.com/rowselector.aspx

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:ey*************@tk2msftngp13.phx.gbl...
Take a look at
http://www.metabuilders.com/Tools/Ro...torColumn.aspx

HTH,
Greg

"magmo" <ma****@rad-o-resultat-dot-se.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
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
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randy | last post by:
Hello, I'm creating a table on the fly that is used by a datagrid. I'm also creating a tableStyle that is used for the datagrid to make it look like I want. I'm using the DataGridBoolColumn to...
1
by: Jim Ptak via .NET 247 | last post by:
I am desperate for help. I am at a loss. I have a dataset with 4columns in it. The first column is an actual column from adatabase table. The last three columns are hard codded values of0. I am using...
5
by: jdipalmajr | last post by:
I have a table which is being displayed in a DataGrid. One of the columns is a boolean. When I began my development, I wasn't using styles to control column formats. When I used the default...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
4
by: pmclinn | last post by:
Below is the code I'm using to dynamically fill a datagrid from a datatable (fed by an ole connection). Everything is working great except that my users have to click 2 time on the checkbox to...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
8
by: cptuser | last post by:
Hi, I've put together this javascript taken from various sources, but i think it is wrong or missing something. If particular options are selected within a drop down menu, then the check botton...
3
by: Soulless | last post by:
Hi, I am very new to C# and am trying to figure out DataGrids. I have a DataGrid whos data member (I think that is what it is called) has a checkbox on it. The checkbox defaults to a check that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.