Solved

Datagrid Select All

Posted on 2004-08-27
15
177 Views
Last Modified: 2010-05-18
What code do i use to select all records in a datagrid
0
Comment
Question by:daverichardson
  • 6
  • 6
15 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 11917756
What do you mean select all records in a datagrid? Do you mean basically looping through the entire grid for values?
0
 

Author Comment

by:daverichardson
ID: 11917772
Yes
0
 
LVL 7

Expert Comment

by:natloz
ID: 11917854
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
0
 

Author Comment

by:daverichardson
ID: 11917986
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
0
 
LVL 7

Expert Comment

by:natloz
ID: 11918006
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.
0
 
LVL 7

Expert Comment

by:natloz
ID: 11918022
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.
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.

 

Author Comment

by:daverichardson
ID: 11918068
that works but i want to highlight the rows so i can copy them
0
 
LVL 7

Expert Comment

by:natloz
ID: 11918081
What are you copying them to? All Columns are being copied including hidden ones?
0
 

Author Comment

by:daverichardson
ID: 11918096
i want to copy them to the clipboard
0
 

Author Comment

by:daverichardson
ID: 11923495
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
0
 
LVL 7

Accepted Solution

by:
natloz earned 50 total points
ID: 11946200
http://www.thecodeproject.com/csharp/PracticalGuideDataGrids4.asp#_Toc56951064

Goto section 5.5...I think this is what you are looking for...
0
 

Author Comment

by:daverichardson
ID: 11977885
Natloz this is exactly what i want, however i need it in vb not c

Dave
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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

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

22 Experts available now in Live!

Get 1:1 Help Now