Solved

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

Posted on 2004-10-05
8
337 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 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