How to select all rows in a DataGrid?

K

Kevin Hodgson

I have a standard .NET Datagrid (Databound to a SQL Dataset), and I need to
select all rows of the datagrid when a button is clicked, to allow a user to
copy the data, and then paste it into Excel or another application. They
need to be able to do this because the application is running on a Terminal
Server in Application Server Mode, and they need to copy the data to an
Excel worksheet on their local computer.

I can do this manually by Clicking on the first row, and then scrolling
through the Datagrid and Shift-Clicking the last row, then using Ctrl-C and
Ctrl-V to copy and paste. But the Datagrid is very large (5-10,000 rows),
and it takes an unacceptable amount of time for the users to scroll through
the entire Datagrid to Shift-Click the last row.

Does anyone have any suggestions on how to do this?

Thanks
 
N

Not Aaron

I tried the following and it worked fine:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i As Integer = 0
While (CStr(dg.Item(i, 1)) <> "")
On Error GoTo err
dg.Select(i)
i += 1
End While
err:
End Sub

That would be a lot easier if you store the rowcount somewhere. I had
a problem with the datagrids visiblerowcount function awhile back, so I
dont use it anymore. If you have access to the dataset, you can use
the row.count function there also. Let me know if that helps.
 
K

Kevin Hodgson

Fantastic, that works like a charm.

I was stuck trying to figure out how many rows the Datagrid actually had.
Didn't occur to me to use the dataset row count.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top