Solved

Implement a sliding window textbox

Posted on 2008-11-02
4
515 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hard to say without testing, but I'd say the difference is minimal; the same mechanisms are used in both cases.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

17 Experts available now in Live!

Get 1:1 Help Now