Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple ListBox question

Status
Not open for further replies.

stylonurus

Programmer
Jun 7, 2006
19
US
After I add a line of text into a ListBox, I would like to make that line visible. That is I would like to see the last 4 lines. The user can scroll up but when a new line is added I want to insert that that line at the bottom and have it displayed as well. Can anybody please help me.

Also, I am somewhat new to Borland C++ Builder 6. (Several months on this C++ application) Where is the best place to get questions like this answered? This is the first site I have left a message on. Perhaps its here. Thanks

Rick
 
OK, let me see if I understand you correctly. First, you want to add an item to the end of a list box. Make sure your ListBox Sorted property is set to false. You can add an item via:
Code:
MyListBox->Items->("Something added");

Next you want to make sure the list box displays the last item. Try something like:
Code:
int ItmInt = MyListBox->Items->Count; // The number of items in list box
if (ItmInt > 0) // There is something in the list box
{
    MyListBox->Selected[ItmInt]; // Last item selected
}

See if this is close to what you want. Also, for further reading try:

As far where to go to get answers, you found a great place here. ;-)

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
A Simple way to do what you want is this:

Code:
// add a string to the listbox
MyListBox->Items->Add(MyAnsiString);
// set the ItemIndex to the last string added
MyListBox->ItemIndex = MyListBox->Count;
 
James,
Thanks so much for your response. I'm going to try it but I also have found something a bit different that works.

MyListBox->ItemIndex = LineCount;

where LineCount has the index value of the last line in the List Box.

Take care

Rick Eis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top