Solved

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

Posted on 2004-10-05
8
331 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
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12226148
I need a VB.NET example....:(
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now