Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi Victor;

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.
Avatar of Victor  Charles

ASKER

Hi,


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.
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(Application.StartupPath + "\Country.xml", IO.FileMode.Open)
        dtset1.ReadXml(fs1)
        fs1.Close()
        Me.C1TrueDBGrid3.DataSource = dtset1.Tables(0)
        Me.C1TrueDBGrid3.Columns(1).Visible = False
        C1TrueDBGrid3.DataSource = dt.DefaultView.ToTable(True, New String() {"Country"})

Victor
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.Insert(0, CheckBoxCol)
    End Sub
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.Count

        Me.C1TrueDBGrid3.ClearSelection()
        'Loop through rows and add each to the selected rows collection

        For i = 0 To count - 1
            Me.C1TrueDBGrid3.SelectedRows.Add(i)
        Next
What happens when you use the code I posted?
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.
Thank You!