Solved

VB.Net Datagridview adding items

Posted on 2011-03-11
5
666 Views
Last Modified: 2012-05-11
I have a datagridview that is constantly having data added to it (read through a serial port), and it has 5 columns.  My manager wants the most recent items to be added to the top, not the bottom which is the default way, so that anyone observing can actually see that data is coming in.

The way I am doing this right now is to do a sort on one particular column (date), so the latest shows at the top.

The problem is that when the datagridview has a few thousand rows, and I have to keep doing this sorting, it takes the CPU usage to 100% constantly.  

My question is this:  is there a way to have it so that when you datagridview.rows.add, for the data to automatically be added to the top of the datagrid, so I don't have to keep doing a sort?

Thanks.
0
Comment
Question by:LD147
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:4runnerfun
ID: 35109712
I don't have the answer for adding data to the top, but if the idea is to keep the latest entry in view, you can have the datagridview auto focus on the last line.

Which looks like it's been addressed here before.
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21625418.html

Quote-
I hade add  DataGrid1.CurrentRowIndex = CType(DataGrid1.DataSource, DataSet).Tables(0).Rows.Count() AFTER a functions format the grid(cell size,align etc) then it worked finde.


Also addressed here:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22121460.html


======= hmm more...

adding at top... possibly
http://stackoverflow.com/questions/5104563/datagridview-add-new-entries-at-the-top

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22606378.html
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 35109901
if you are manually adding the data to the datagridview, use the insert method to insert at 0 (line zero)
0
 
LVL 1

Author Comment

by:LD147
ID: 35110185
Nepaluz:  that works perfectly and is exactly what I need!  Thank you!

4runnerfun: Using CurrentRowIndex also is ok, as it sets the focus to the bottom of the grid.  I would have used this if Nepaluz hadn't given me his information.  Thank you for the suggestion.
0
 
LVL 3

Expert Comment

by:4runnerfun
ID: 35110229
Np, the last link I listed was about the insert method.. ;) but it's all good. Glad you got what you needed.
0
 
LVL 1

Author Comment

by:LD147
ID: 35110263
Ahhh....I checked the first two links of yours, and I was going to accept the CurrentRowIndex method, then I saw Nepaluz's message....lol.  Thanks again! :)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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