-
Jan 13th, 2015, 09:43 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] ListBox SelectedIndex in C#
In .NET, ListBox has a very good feature to de-select all by .SelectedIndex =-1
From what I know, VB6's Listbox ListIndex just set or return Focus (not Selected), it is totally differ to .Net SelectedIndex.
Right now I coded .NET SelectedIndex = -1 in VB6 by two steps:
lstGoods.ListIndex = -1 'Get rid of Focus at first
Call SendMessage(lstGoods.hWnd, LB_SETSEL, 0, ByVal -1) 'De-select all
Question 1:
Is my above code for lstGoods.SelectedIndex = -1 right?
Question 2:
How to achieve the same thing for:
C#:
this.lstGoods().TopIndex = this.lstGoods().SelectedIndex
Last edited by Jonney; Jan 13th, 2015 at 09:46 AM.
-
Jan 13th, 2015, 10:05 AM
#2
Re: ListBox SelectedIndex in C#
#1: Yes. Here's the documentation. You can always look up the window message on MSDN to answer the question yourself. LB_SETSEL is used for multi-select listboxes. A single-select would just need the ListIndex = -1
Parameters
wParam
Specifies how to set the selection. If this parameter is TRUE, the item is selected and highlighted; if it is FALSE, the highlight is removed and the item is no longer selected.
lParam
Specifies the zero-based index of the item to set. If this parameter is –1, the selection is added to or removed from all items, depending on the value of wParam, and no scrolling occurs.
#2. VB's ListBox also has a TopIindex property
-
Jan 13th, 2015, 07:03 PM
#3
Thread Starter
Frenzied Member
Re: ListBox SelectedIndex in C#
Last edited by Jonney; Jan 13th, 2015 at 08:26 PM.
-
Jan 13th, 2015, 07:11 PM
#4
Re: ListBox SelectedIndex in C#
Which language are you using? I assume it is VB6 but the way the originally post is written it is a bit unclear.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jan 13th, 2015, 07:33 PM
#5
Thread Starter
Frenzied Member
Re: ListBox SelectedIndex in C#
Originally Posted by Nightwalker83
Which language are you using? I assume it is VB6 but the way the originally post is written it is a bit unclear.
VB6.
I wrote a small project in C#, but now I want to wrote same thing in VB6 with some enhancement. But look like VB6 is harder. I have to look for APIs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|