Victor Charles
asked on
Help with selecting all row in DataGridView using VB.NET
Hi,
If My DataGrid contains
BEL
CAN
USA
When I click on the All button, how do I obtain
BEL,CAN,USA
Thanks,
Victor
If My DataGrid contains
BEL
CAN
USA
When I click on the All button, how do I obtain
BEL,CAN,USA
Thanks,
Victor
ASKER
Hi,
Can you please send the code on how to achieve this,
Thanks,
Victor
Can you please send the code on how to achieve this,
Thanks,
Victor
How do you fill the DataGrid?
What is the source of the data?
What is the Column name that the data is stored in?
Please post your code.
What is the source of the data?
What is the Column name that the data is stored in?
Please post your code.
ASKER
Hi,
I am using the following code to load the Grid.
Dim dtset1 As New DataSet
Dim fs1 As System.IO.FileStream
fs1 = New System.IO.FileStream(Appli cation.Sta rtupPath + "\Country.xml", IO.FileMode.Open)
dtset1.ReadXml(fs1)
fs1.Close()
Me.C1TrueDBGrid3.DataSourc e = dtset1.Tables(0)
Me.C1TrueDBGrid3.Columns(1 ).Visible = False
C1TrueDBGrid3.DataSource = dt.DefaultView.ToTable(Tru e, New String() {"Country"})
Victor
I am using the following code to load the Grid.
Dim dtset1 As New DataSet
Dim fs1 As System.IO.FileStream
fs1 = New System.IO.FileStream(Appli
dtset1.ReadXml(fs1)
fs1.Close()
Me.C1TrueDBGrid3.DataSourc
Me.C1TrueDBGrid3.Columns(1
C1TrueDBGrid3.DataSource = dt.DefaultView.ToTable(Tru
Victor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm afraid all the rows were not selected, the DataGrid also contains a column with checkboxes, could that be why the code does not work? Code below is in button click event to display data in the Grid.
Private Sub CheckControl()
Dim CheckBoxCol As New DataGridViewCheckBoxColumn
With CheckBoxCol
.Name = "CheckBoxColumn"
.HeaderText = "Select"
.Width = 40
End With
Me.C1TrueDBGrid3.Columns.I nsert(0, CheckBoxCol)
End Sub
Private Sub CheckControl()
Dim CheckBoxCol As New DataGridViewCheckBoxColumn
With CheckBoxCol
.Name = "CheckBoxColumn"
.HeaderText = "Select"
.Width = 40
End With
Me.C1TrueDBGrid3.Columns.I
End Sub
ASKER
Hi,
Below is the code that worked with a third party Grid (ComponentOne), but
getting error message related to splits for the DataGrid.
Error: Splits is not a member of DataGridView
Dim count As Integer = Me.C1TrueDBGrid3.Splits(0) .Rows.Coun t
Me.C1TrueDBGrid3.ClearSele ction()
'Loop through rows and add each to the selected rows collection
For i = 0 To count - 1
Me.C1TrueDBGrid3.SelectedR ows.Add(i)
Next
Below is the code that worked with a third party Grid (ComponentOne), but
getting error message related to splits for the DataGrid.
Error: Splits is not a member of DataGridView
Dim count As Integer = Me.C1TrueDBGrid3.Splits(0)
Me.C1TrueDBGrid3.ClearSele
'Loop through rows and add each to the selected rows collection
For i = 0 To count - 1
Me.C1TrueDBGrid3.SelectedR
Next
What happens when you use the code I posted?
ASKER
You code works, but I was not clear in my question, I also would like to select all the rows when I press the all button and clear all the row when I click on the clear button. If necessary I can create another post.
Thanks.
Thanks.
ASKER
Thank You!
Seeming you want all rows you will need to enumerate through all the rows of the DataGrid and build the string from the column that has BEL, CAN, USA in it.