Solved

VB.Net Datagridview adding items

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now