Hi,
This can very easily be achieved if you're using VB.NET. Here's an example:
1. I have a list box named lstBox. It's got a couple of items added to it beforehand. I add a new item:
lstBox.Items.Add ( "NewItem" )2. Now the number of items in a listbox is returned if you call the
Count method of ListBox.Items. So:
lstBox.Items.Count - will give me the total item count including the newly inserted item.
3. Now third step is to select the last item - which can be achieved by using the
SelectedIndex method of Listbox. SelectedIndex accepts an integer as it's parameter to indicate which item to select. Keep in mind, that this index is ZERO based. So the indices of the items in the list, start from
0 ..upto.. (n-1), where n = lstBox.Items.CountSo all I need to do is,
lstBox.SelectedIndex = lstBox.Items.Count - 1 - this single line will do the trick

Hope this helps...
Regards,
m^e
Reply