Solved

VB.Net Datagridview adding items

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with exporting to excel 4 46
ASP/VB email question 4 63
VB.NET 2008 - Windows Protected Your PC 7 56
Create a datatable in vb.net dynamically 1 40
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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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