Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,059 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,580 people online right now. Registration is fast and FREE... Join Now!




getting the cursor to the last item in listbox

 
Reply to this topicStart new topic

getting the cursor to the last item in listbox, listbox to scroll so that the user sees the last line

johnholton
22 Apr, 2008 - 03:48 AM
Post #1

New D.I.C Head
*

Joined: 22 Apr, 2008
Posts: 4

csharp

public void displayStatus(string msg)
{
if (lstStatus.InvokeRequired)
{
object[] parms = { msg };
lstStatus.Invoke(new displayStatusDelegate(displayStatus), parms);

}
else
{
if (msg.Length < 80)
{
lstStatus.Items.Add(msg);

}
else
{
string[] a = msg.Split(',');
foreach (string s in a)
{
lstStatus.Items.Add("," + s);
}
}

//this line partially achieves what I am looking for, but results in the line being
//selected. i just want the cursor to be on the last line
lstStatus.SelectedIndex = lstStatus.Items.Count - 1;

}
}


EDIT: Code blocks added

This post has been edited by PsychoCoder: 22 Apr, 2008 - 04:30 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Getting The Cursor To The Last Item In Listbox
22 Apr, 2008 - 04:48 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Try this


csharp

public void displayStatus(string msg)
{
if (lstStatus.InvokeRequired)
{
object[] parms = { msg };
lstStatus.Invoke(new displayStatusDelegate(displayStatus), parms);

}
else
{
if (msg.Length < 80)
{
lstStatus.Items.Add(msg);

}
else
{
string[] a = msg.Split(',');
foreach (string s in a)
{
lstStatus.Items.Add("," + s);
}
}

lstStatus.SelectedIndex = lstStatus.Items.Count - 1;
lstStatus.SelectedIndex = -1;
}
}

User is offlineProfile CardPM
+Quote Post

johnholton
RE: Getting The Cursor To The Last Item In Listbox
22 Apr, 2008 - 12:43 PM
Post #3

New D.I.C Head
*

Joined: 22 Apr, 2008
Posts: 4

thanks

that worked a treat
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Getting The Cursor To The Last Item In Listbox
22 Apr, 2008 - 01:01 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8525
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:23PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month