Answered by:
MultiSelect Listbox

Question
-
Hello
How can I create a listbox that I can Multiselect from this listbox ?
Does .Net Compact Framewrok 3.5 have Multiselect Listbox ?Thursday, September 3, 2009 12:03 PM
Answers
-
Hi Kemal,
As far as I know, Listbox control doesn't support multi select in CF. We can use ListView instead, here we have two options:
1. Use Listview with checkbox enabled, we can check checkbox to implement multi selection.
2. P/Invoke native API to change Listview property to implement multi selection, like the code below:
private const int GWL_STYLE = -16;
private const int LVS_SINGLESEL = 0x0004;
[DllImport("coredll")]
private static extern IntPtr GetCapture();
[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwLong);
private void Form1_Load(object sender, EventArgs e)
{
this.listView1.Capture = true;
IntPtr hWnd = GetCapture();
this.listView1.Capture = false;
int style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, (style & ~LVS_SINGLESEL));
}
Best regards,
Guang-Ming Bian - MSFT
Please remember to mark the replies as answers if they help and unmark them if they provide no help- Marked as answer by Guang-Ming Bian - MSFT Wednesday, September 9, 2009 2:48 AM
Monday, September 7, 2009 6:42 AM
All replies
-
Hi,
The following forum thread may help you :-
http://www.eggheadcafe.com/conversation.aspx?messageid=31276982&threadid=31276982
Hope this helps.
Paul Diston
http://www.smartmobiledevice.co.uk/Thursday, September 3, 2009 12:06 PM -
Hi Kemal,
As far as I know, Listbox control doesn't support multi select in CF. We can use ListView instead, here we have two options:
1. Use Listview with checkbox enabled, we can check checkbox to implement multi selection.
2. P/Invoke native API to change Listview property to implement multi selection, like the code below:
private const int GWL_STYLE = -16;
private const int LVS_SINGLESEL = 0x0004;
[DllImport("coredll")]
private static extern IntPtr GetCapture();
[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwLong);
private void Form1_Load(object sender, EventArgs e)
{
this.listView1.Capture = true;
IntPtr hWnd = GetCapture();
this.listView1.Capture = false;
int style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, (style & ~LVS_SINGLESEL));
}
Best regards,
Guang-Ming Bian - MSFT
Please remember to mark the replies as answers if they help and unmark them if they provide no help- Marked as answer by Guang-Ming Bian - MSFT Wednesday, September 9, 2009 2:48 AM
Monday, September 7, 2009 6:42 AM