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
Solved

VB.Net Datagridview adding items

Posted on 2011-03-11
5
667 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

789 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