Solved

Implement a sliding window textbox

Posted on 2008-11-02
4
519 Views
Last Modified: 2008-11-03
Hi,
I am looking for the most efficient way to create a textbox to monitor comms data.

I need to limit it's size to 100 lines so when a new line arrives, it is added to the bottom and if the no. lines in the textbox >100 the first one is removed.

The behaviour would be similar to that of the hyperterminal window (cant see all data just latest x lines).

I need to do this in a highly performant manner.
Please advise on the best way to go about it. ps. not wedded to a text box so use another control if it suits.

(using visual studio 2005)

thanks.
Shaun
0
Comment
Question by:sdom100
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
alex_paven earned 450 total points
ID: 22863704
One way would be using a listbox, setting its datasource to a System.ComponentModel.BindingList<string> and working with the bindinglist; any changes you make in the list will be reflected in the control. If you need a textbox or similar control, you can inherit the bindinglist and provide a member that concatenates properly the list contents (100 is a relatively 'low' number for a stringbuilder, but calling it in a tight loop would indeed decrease performance). Other alternatives would include building a custom control that keeps track of changes in the list and paints the list as you see fit.
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 50 total points
ID: 22864247
My first thought was same as alex_paven's idea. I'd use a ListBox with the datasourse of the List<string> datatype. But I'd write my own class for this datasource List that would inherit from List<>. Basicly, I'd rewrite an Add() where I'd track number of lines and cleared items at the beginning of the list etc.
0
 

Author Comment

by:sdom100
ID: 22865261
My latest approach was to go with the listbox as suggested and simply use the add, check the items.count if >100 then use the RemoveAt function to take off the first line.
Which is most efficient ? (this way or using binding as per your suggestions) ?

Thanks,
Shaun
0
 
LVL 6

Expert Comment

by:alex_paven
ID: 22865270
Hard to say without testing, but I'd say the difference is minimal; the same mechanisms are used in both cases.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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