[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Select multiple columns of a datagridview in Vb.net

Posted on 2013-12-13
4
Medium Priority
?
1,521 Views
Last Modified: 2014-01-07
I usually use the datagridview.SelectAll() and copy/paste the grid to Excel.  Today, I just want to copy/paste the first two columns of the datagridview.  How do I do this?  

Thanks!
0
Comment
Question by:Karen Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1500 total points
ID: 39716845
You can select individual columns like:
            dataGridView1.Columns[0].Selected = true;
            dataGridView1.Columns[1].Selected = true;

Open in new window

But you will also have to make sure that the SelectionMode property is set to FullColumnSelect
0
 

Author Comment

by:Karen Wilson
ID: 39716879
I tried to change selectionmode to full column select and it said that I had to change all the columns in my grid from automatic to something else.  So I did that and this code works.  The problem is, my users need the ability to sort the columns so I guess I program the columns to sort asc/dsc when they get clicked.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39755039
You can disable sorting when exporting to Excel and enable it again when done exporting.
0
 

Author Comment

by:Karen Wilson
ID: 39761861
What I finally did was approach it from a different angle and used Note Pad.  Below is my code.

Dim getDoc = (From id In d.tblAddBooks _
                                Where id.Christmas = "Yes" _
                                And id.Status = "Active" _
                                Order By id.People Ascending, id.StartDate Descending _
                                Select id).ToList

        If getDoc.Count > 0 Then

            Dim pr As Process = New Process

            Dim docString As New StringBuilder()

            For i As Integer = 0 To getDoc.Count - 1

                Dim n As String = CStr(getDoc.Item(i).People)
                Dim s As String = CStr(getDoc.Item(i).Street)
                Dim cS As String = CStr(getDoc.Item(i).City_State)
                Dim z As String = CStr(getDoc.Item(i).Zip)
                Dim ph As String = CStr(getDoc.Item(i).homePhone)

                docString.Append(n & " - " & s & " - " & cS & " " & z & vbCrLf)
            Next

            pr.StartInfo.FileName = "notepad.exe"
            pr.Start()
            pr.WaitForInputIdle()

            SendKeys.Send(docString.ToString)
        Else
            MsgBox("There are no records.", MsgBoxStyle.OkOnly, "Send to Note Pad")
        End If
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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