Solved

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

Posted on 2004-10-05
8
332 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

911 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

23 Experts available now in Live!

Get 1:1 Help Now