Karen Wilson
asked on
Select multiple columns of a datagridview in Vb.net
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!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can disable sorting when exporting to Excel and enable it again when done exporting.
ASKER
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_S tate)
Dim z As String = CStr(getDoc.Item(i).Zip)
Dim ph As String = CStr(getDoc.Item(i).homePh one)
docString.Append(n & " - " & s & " - " & cS & " " & z & vbCrLf)
Next
pr.StartInfo.FileName = "notepad.exe"
pr.Start()
pr.WaitForInputIdle()
SendKeys.Send(docString.To String)
Else
MsgBox("There are no records.", MsgBoxStyle.OkOnly, "Send to Note Pad")
End If
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_S
Dim z As String = CStr(getDoc.Item(i).Zip)
Dim ph As String = CStr(getDoc.Item(i).homePh
docString.Append(n & " - " & s & " - " & cS & " " & z & vbCrLf)
Next
pr.StartInfo.FileName = "notepad.exe"
pr.Start()
pr.WaitForInputIdle()
SendKeys.Send(docString.To
Else
MsgBox("There are no records.", MsgBoxStyle.OkOnly, "Send to Note Pad")
End If
ASKER