Solved

Datagrid Select All

Posted on 2004-08-27
15
174 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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