Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How can i insert a check box in each row of a DataGrid????

Posted on 2004-10-05
8
335 Views
Last Modified: 2010-04-23
How can i insert a check box in each row of a datagrid after i put data into the datagrid with a "SELECT * FROM Table"???

And how can i refer to the rows that have the check boxes checked???

It's URGENT.

Thanks.
0
Comment
Question by:drcyrus3d
  • 4
  • 2
  • 2
8 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12226042
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 50 total points
ID: 12226074
>>How do I determine whether a checkbox in my datagrid is checked or not?<<
If the column is a boolean column, you can just cast the object returned by the indexer to a bool and use it.
 
If CType(dataGridTopics(row, column),Boolean) Then
     MessageBox.Show("I am true")
else  
     MessageBox.Show("I am false")
End If
0
 
LVL 3

Expert Comment

by:RacinRan
ID: 12226138
I used a table style and added my checkbox column as a DataGridBoolColumn.  I actually have mine mapped to a datasource, but this is a boolean column so no need to Ctype it.

Racin
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:drcyrus3d
ID: 12226148
I need a VB.NET example....:(
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12226165
The previous message was for the first reply..... :D

I need some code example...pls. Thanks.
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12226184
i found this code for checking if a checkbox is checked or not.

Private Sub GetSelections_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetSelections.Click
        Dim rowCount As Integer = 0
        Dim gridSelections As StringBuilder = New StringBuilder()

        'Loop through each DataGridItem, and determine which CheckBox controls
        'have been selected.
        Dim DemoGridItem As DataGridItem
        For Each DemoGridItem In DemoGrid.Items

            Dim myCheckbox As CheckBox = CType(DemoGridItem.Cells(0).Controls(1), CheckBox)
            If myCheckbox.Checked = True Then
                rowCount += 1
                gridSelections.AppendFormat("The checkbox for {0} was selected<br>", _
                                            DemoGrid.DataKeys(DemoGridItem.ItemIndex).ToString())
            End If
        Next
        gridSelections.Append("<hr>")
        gridSelections.AppendFormat("Total number selected is: {0}<br>", rowCount.ToString())
        ResultsInfo.Text = gridSelections.ToString()

End Sub

Now i want to know how to add that checkbox to my datagrid.
0
 
LVL 3

Assisted Solution

by:RacinRan
RacinRan earned 450 total points
ID: 12226304
       Dim oTS As New DataGridTableStyle
        Dim oCol As New DataGridTextBoxColumn
        Dim oBoolCol as New DataGridBoolColumn

        oTS.MappingName = "MyDataSource"  'MappingName maps fields in your query to fields in the grid.

'A Field In select statement
        With oCol
            .MappingName = "Priority"
            .HeaderText = "Priority"
            .Width = 25
        End With
        oTS.GridColumnStyles.Add(oCol)

'Another Field in select statement
        With oCol
            .MappingName = "EquipReqID"
            .HeaderText = "ERID"
            .Width = 50
        End With
        oTS.GridColumnStyles.Add(oCol)

'My Bool not in in select statement, do not set mapping name
        With oBoolCol
            .HeaderText = "ERID"
            .Width = 50
        End With
        oTS.GridColumnStyles.Add(oBoolCol)

dgEquipRequest.TableStyles.Add(oTS)  'When this datasource is used for this grid, this tablestyle will be used for what you see in the grid.

Racin

0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12226799
Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
write xml in vb.net 2 32
VB.NET 2008 Winforms Signing 13 30
How to limit User Input 2 27
How to extract certain lines from textfile and save them to another file? 6 26
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question