Link to home
Start Free TrialLog in
Avatar of daverichardson
daverichardson

asked on

Datagrid Select All

What code do i use to select all records in a datagrid
Avatar of natloz
natloz

What do you mean select all records in a datagrid? Do you mean basically looping through the entire grid for values?
Avatar of daverichardson

ASKER

Yes
dim intRowCount as integer = dgGrid.VisibleRowCount
dim intCount as integer = 0

If dgGrid.VisibleRowCount < 1 Then
            MsgBox("Nothing in GRID")
Else
            Dim oSelectedItem As Object
            Dim strBLAH As String

            Do while intCount < (intRowCount - 1)  <-----I used -1 because 30 Rows...means 0 to 29 for RowNumbers
                oSelectedItem = dgGrid.Item(intCount, 3) <--- 3 is any COLUMN Number you wish to read
                strBLAH = CStr(oSelectedItem)
                intCount = intCount + 1
            Loop            
End If
i dont know what i am missing but nothing happened

    Private Sub MnuSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuSelectAll.Click
        Dim intRowCount As Integer = GrdOrders.VisibleRowCount
        Dim intCount As Integer = 0

        If GrdOrders.VisibleRowCount < 1 Then
            MsgBox("Nothing in GRID")
        Else
            Dim oSelectedItem As Object
            Dim strBLAH As String

            Do While intCount < (intRowCount - 1)
                oSelectedItem = GrdOrders.Item(intCount, 3)
                strBLAH = CStr(oSelectedItem)
                intCount = intCount + 1

            Loop
        End If
    End Sub
Well....what do you want to do with the results? You will see what my solution is doing if you add

Do While intCount < (intRowCount - 1)
                oSelectedItem = GrdOrders.Item(intCount, 3)
                strBLAH = CStr(oSelectedItem)
                intCount = intCount + 1
                msgbox (strBlah)
            Loop

I am just showing you how to loop through the whole Grid and pick up results from each row.
Well....what do you want to do with the results? You will see what my solution is doing if you add

Do While intCount < (intRowCount - 1)
                oSelectedItem = GrdOrders.Item(intCount, 3)
                strBLAH = CStr(oSelectedItem)
                intCount = intCount + 1
                msgbox (strBlah) <-------------- ADD THIS (Forgot to show you where adding)
            Loop

I am just showing you how to loop through the whole Grid and pick up results from each row.
that works but i want to highlight the rows so i can copy them
What are you copying them to? All Columns are being copied including hidden ones?
i want to copy them to the clipboard
The easiest way to explain what I want is, within a Datagrid if you press ctrl-a to select the records and ctrl-c to copy but I want to do this with a menu
ASKER CERTIFIED SOLUTION
Avatar of natloz
natloz

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
Natloz this is exactly what i want, however i need it in vb not c

Dave