473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to select all rows in a DataGrid?

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


Nov 21 '05 #1
2 10675
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.

Nov 21 '05 #2
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.
"Not Aaron" <aa**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: Raj Chudasama | last post by:
how can i select all rows in a datagrid also how can add checkbox to each of my rows in datagrid. I tried to use DataGridColumnStyle but failed try {
7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
3
by: Zachary Hilbun | last post by:
I'm using a DataGrid control in a web form. I can display it using binding but when I click on any of the items there is no feedback that that row has been selected. I changed SelectedItemStyle...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
1
by: chreo | last post by:
Hello. Does anybody had problem with VB application with MS SQL Database? I have DATAGRID which shows TABLE from DATABASE. Next I add new ROW to TABLE with SQLcommand (stored procedure) ...
0
by: WhiteWizard | last post by:
I am trying to implement standard multi-select of rows in a datagrid. That is, allow the user to use the CTRL & SHIFT keys to select multiple rows in a datagrid. Then I'll loop through them and...
3
by: joelzn | last post by:
I have a hand built dataset where some columns come from a sql database and others are calculated and eventually I will have two different query results going into one table because its impossible...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.