473,698 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid with checkbox and SQL

Hi !

I'm trying to use a datagrid with an checkbox column, I not shoure to
get it work on several points

I have got the rest of the data mapped to the grid but the checkbox
doesnt work.

1. The column type in the sql is Integer (values 0 or 1), is this ok or
should I change it to something else?

2. my code to load the grid

Sub LoadDataToGrid( )

formatdatagrid( )
DataSet11.Clear ()

DataGrid1.DataS ource = (DataSet11)
DataGrid1.DataM ember = "RAT_Custom er"
SqlDataAdapter1 .SelectCommand. CommandText = "Select CustomerCode
as KundNr, SL01002 as KundNamn ,Pfaktor as Påslag, InOutputFile from
RAT_Customer, SL010100 where CustomerCode = SL01001"
SqlConnection1. Open()

SqlDataAdapter1 .Fill(DataSet11 )

SqlConnection1. Close()

End Sub
3. My code to format the grid

Dim grdColStyle1 As New DataGridTextBox Column
With grdColStyle1
.HeaderText = "Kund Nr"
.MappingName = "KundNr"
.Width = 50
End With

Dim grdColStyle2 As New DataGridTextBox Column
With grdColStyle2
.HeaderText = "Namn"
.MappingName = "KundNamn"
.Width = 90
End With

Dim grdColStyle3 As New DataGridTextBox Column
With grdColStyle3
.HeaderText = "Påslag traktamente (SEK)"
.MappingName = "Påslag"
.Width = 140
'.ReadOnly = True
End With

Dim grdColStyle4 As New DataGridBoolCol umn
With grdColStyle4
.HeaderText = "Överföring till RAT"
.MappingName = "InOutputFi le"
.Width = 130
.Alignment = HorizontalAlign ment.Center
.ReadOnly = False

End With

' Add the style objects to the table style's collection of
' column styles. Without this the styles do not take effect.
grdTableStyle1. GridColumnStyle s.AddRange _
(New DataGridColumnS tyle() _
{grdColStyle1, grdColStyle2, grdColStyle3, grdColStyle4})
DataGrid1.Table Styles.Add(grdT ableStyle1)
I should be very happy if anyone could tell whats wrong or whats missing
Nov 20 '05 #1
2 1150
Hi,

It does not look like you are setting up your tablestyle right. Here
is an example using the northwind database. I assume you have the
northwind.mdb in the bin directory of your project folder and imports
system.data.ole db at the top of your file.

Public ds As New DataSet

Dim dv As DataView

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapte r

strConn = "Provider = Microsoft.Jet.O LEDB.4.0;"

strConn += "Data Source = Northwind.mdb;"

conn = New OleDbConnection (strConn)

da = New OleDbDataAdapte r("Select * From Products", conn)

da.Fill(ds, "Products")

SetupGrid()

dv = New DataView(ds.Tab les("Products") )

With dv

..AllowNew = False

..AllowEdit = True

..AllowDelete = False

End With

DataGrid1.DataS ource = dv

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableSt yle

ts.MappingName = "Products"

Dim colName As New DataGridTextBox Column

With colName

..MappingName = "ProductNam e"

..HeaderText = "Name"

..Width = 200

End With

Dim colDiscontinued As New DataGridBoolCol umn

With colDiscontinued

..MappingName = "Discontinu ed"

..HeaderText = "Discontinu ed"

..Width = 80

End With

ts.GridColumnSt yles.Add(colNam e)

ts.GridColumnSt yles.Add(colDis continued)

DataGrid1.Table Styles.Add(ts)

ts = Nothing

colName = Nothing

colDiscontinued = Nothing

End Sub

Ken
-------------------

"Thomas A" <th************ **@msn.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
Hi !

I'm trying to use a datagrid with an checkbox column, I not shoure to
get it work on several points

I have got the rest of the data mapped to the grid but the checkbox
doesnt work.

1. The column type in the sql is Integer (values 0 or 1), is this ok or
should I change it to something else?

2. my code to load the grid

Sub LoadDataToGrid( )

formatdatagrid( )
DataSet11.Clear ()

DataGrid1.DataS ource = (DataSet11)
DataGrid1.DataM ember = "RAT_Custom er"
SqlDataAdapter1 .SelectCommand. CommandText = "Select CustomerCode
as KundNr, SL01002 as KundNamn ,Pfaktor as Påslag, InOutputFile from
RAT_Customer, SL010100 where CustomerCode = SL01001"
SqlConnection1. Open()

SqlDataAdapter1 .Fill(DataSet11 )

SqlConnection1. Close()

End Sub
3. My code to format the grid

Dim grdColStyle1 As New DataGridTextBox Column
With grdColStyle1
.HeaderText = "Kund Nr"
.MappingName = "KundNr"
.Width = 50
End With

Dim grdColStyle2 As New DataGridTextBox Column
With grdColStyle2
.HeaderText = "Namn"
.MappingName = "KundNamn"
.Width = 90
End With

Dim grdColStyle3 As New DataGridTextBox Column
With grdColStyle3
.HeaderText = "Påslag traktamente (SEK)"
.MappingName = "Påslag"
.Width = 140
'.ReadOnly = True
End With

Dim grdColStyle4 As New DataGridBoolCol umn
With grdColStyle4
.HeaderText = "Överföring till RAT"
.MappingName = "InOutputFi le"
.Width = 130
.Alignment = HorizontalAlign ment.Center
.ReadOnly = False

End With

' Add the style objects to the table style's collection of
' column styles. Without this the styles do not take effect.
grdTableStyle1. GridColumnStyle s.AddRange _
(New DataGridColumnS tyle() _
{grdColStyle1, grdColStyle2, grdColStyle3, grdColStyle4})
DataGrid1.Table Styles.Add(grdT ableStyle1)
I should be very happy if anyone could tell whats wrong or whats missing

Nov 20 '05 #2
Hi Ken !

I looked in table "products" in the Nortwind database at my sql Server. It
should be BIT and not Integer at the field.
After the tablechange the grid worked correctly with true and false.

Thank you for opening my eyes
Regards Thomas

Nov 20 '05 #3

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

Similar topics

0
2156
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with these selected fields and allow user to click one or more CheckBox controls to activate this bit on the database table for a required ID. I have already added a template column to the DataGrid and I can get the
4
1515
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn HeaderText="Check In"> <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> <ItemTemplate> <asp:CheckBox id="chkReturn" runat="server" OnCheckedChanged="CheckItIn"></asp:CheckBox>
2
3136
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
2401
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 CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
4
1848
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
7
2275
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 Datagrid that will fire off when the Checkbox is changed? regards /Lars
2
2459
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server checkbox control. where i'm at: i can retrieve a count of the selected checkboxes, but don't know how to get the related id's (in the 1st column).
1
4232
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
3
3146
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 expects a DataGridColumn so I instantiated an object of type TemplateColumn that I had hoped I could add a CheckBox to. I soon discovered that the ItemTemplate property of the TemplateColumn class returned an object that had implemented the...
7
2508
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To implement this, if I am not mistaken, I HAVE TO post the Form first i.e. set the AutoPostBack property of the CheckBox to True. Without posting the Form, I don't think the BackColor of the checked row can be changed using ASP.NET, isn't it? Of...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.