Solved

Implement a sliding window textbox

Posted on 2008-11-02
4
517 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 35
Word Directory is not in the drop down list 4 26
Remove greater than sign 3 50
Windows Media Player 2 18
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

23 Experts available now in Live!

Get 1:1 Help Now