473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Listbox bug ??

Hi all,

I have found that when I have a listbox bound to a datatable, the
ClearSelected method of the listbox does not work properly. It just changes
the selection to item 1 in the listbox. Calling ClearSelected again then
removes the selection.

If the listbox is unbound it works correctly. ie only one call of
ClearSelected is required.

I have tried using listbox.selectedindex = -1
This has the same effect.

Anyone else encountered this ??
Steve

Nov 21 '05 #1
13 1569
Steve,

I am not sure however it seems one of the very well known bugs.
Did you try setting the selectedindex twice to -1 that is mostly the
solution.

I hope this helps,

Cor
I have found that when I have a listbox bound to a datatable, the
ClearSelected method of the listbox does not work properly. It just changes the selection to item 1 in the listbox. Calling ClearSelected again then
removes the selection.

If the listbox is unbound it works correctly. ie only one call of
ClearSelected is required.

I have tried using listbox.selectedindex = -1
This has the same effect.

Anyone else encountered this ??
Steve

Nov 21 '05 #2
On Sat, 14 Aug 2004 12:46:44 +0200, "Cor Ligthert" <no**********@planet.nl>
wrote:
Steve,

I am not sure however it seems one of the very well known bugs.
Did you try setting the selectedindex twice to -1 that is mostly the
solution.


Hi Cor,

Yes both options work if I call them twice. (ie either clearselected, or
..selectedindex=-1). The trouble is it only seems to work once the listbox is
visible.

I have a modal dialog form where I want the selection cleared when the form
is displayed. The above method in my form_load event works for the initial
..showdialog call of the form after it's instantiation, but not after the
form has been hidden by dialogOK/cancel and then called again with
..showdialog. On subsequent calls the first list item is always selected
(even if there was nothing selected when it was closed).

I suppose one option would be to just .dispose the form after each call and
recreate it each time I need it, seeing as it works on the first call.

thanks
Steve

Nov 21 '05 #3
Steve,

Probably you have your code in the load event.
Can you bring that to the New Sub after there where is written.
'Add any initialization after the InitializeComponent() call

I tried it, and than it works for me, in the load event I get the same
problem as you.

I hope this helps?

Cor
On Sat, 14 Aug 2004 12:46:44 +0200, "Cor Ligthert" <no**********@planet.nl> wrote:
Steve,

I am not sure however it seems one of the very well known bugs.
Did you try setting the selectedindex twice to -1 that is mostly the
solution.
Hi Cor,

Yes both options work if I call them twice. (ie either clearselected, or
.selectedindex=-1). The trouble is it only seems to work once the listbox

is visible.

I have a modal dialog form where I want the selection cleared when the form is displayed. The above method in my form_load event works for the initial
.showdialog call of the form after it's instantiation, but not after the
form has been hidden by dialogOK/cancel and then called again with
.showdialog. On subsequent calls the first list item is always selected
(even if there was nothing selected when it was closed).

I suppose one option would be to just .dispose the form after each call and recreate it each time I need it, seeing as it works on the first call.

thanks
Steve

Nov 21 '05 #4
On Sat, 14 Aug 2004 13:54:44 +0200, "Cor Ligthert" <no**********@planet.nl>
wrote:
Steve,

Probably you have your code in the load event.
Can you bring that to the New Sub after there where is written.
'Add any initialization after the InitializeComponent() call

I tried it, and than it works for me, in the load event I get the same
problem as you.

I hope this helps?

Hi Cor,

What I have at the moment:

1. In the New sub I call my InitTable sub, which creates columns in the
datatable and then binds the listbox to it.

2. In my form_load I call a function which populates the datatable with data
from a database. Having this in the form_load means the data is refreshed
every time the form is called with .showdialog.

3. After this I have put my .selectedindex = -1 in the form_load

As I said before this works for the first call but not subsequent ones.

I just tried putting all of the above in my New sub and now it doesn't work
even for the first call. Item 1 is selected, even with 2 x .selectedindex=-1
and 2 x clearselected in the New sub after I populate the datatable.
thanks
Steve

Nov 21 '05 #5
* Steve Cutting <sc******@optusnet.com.au> scripsit:
I have found that when I have a listbox bound to a datatable, the
ClearSelected method of the listbox does not work properly. It just changes
the selection to item 1 in the listbox. Calling ClearSelected again then
removes the selection.

If the listbox is unbound it works correctly. ie only one call of
ClearSelected is required.

I have tried using listbox.selectedindex = -1
This has the same effect.


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #6
On 14 Aug 2004 15:01:56 +0200, hi***************@gmx.at (Herfried K. Wagner
[MVP]) wrote:
* Steve Cutting <sc******@optusnet.com.au> scripsit:
I have found that when I have a listbox bound to a datatable, the
ClearSelected method of the listbox does not work properly. It just changes
the selection to item 1 in the listbox. Calling ClearSelected again then
removes the selection.

If the listbox is unbound it works correctly. ie only one call of
ClearSelected is required.

I have tried using listbox.selectedindex = -1
This has the same effect.


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>


Thanks Herfied. Didn't realise it affected the combo-box too. I was talking
about the listbox

Steve

Nov 21 '05 #7
Steve,

Do you want to select the first item or want you keep it as it was, you
confuse me, because from your previous message I understood that you did
want to keep it in the state you left it?

Cor
Nov 21 '05 #8
On Sat, 14 Aug 2004 15:18:53 +0200, "Cor Ligthert" <no**********@planet.nl>
wrote:
Steve,

Do you want to select the first item or want you keep it as it was, you
confuse me, because from your previous message I understood that you did
want to keep it in the state you left it?


Hi Cor,

I want nothing to be selected in the listbox whenever I call the form with
..showdialog

thanks
Steve
Nov 21 '05 #9
* Steve Cutting <sc******@optusnet.com.au> scripsit:
I have tried using listbox.selectedindex = -1
This has the same effect.


BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>


Thanks Herfied. Didn't realise it affected the combo-box too. I was talking
about the listbox


I assume it's the same bug.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #10
Steve,

This works without any problem for me.

Private Sub Form2_Activated(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.ListBox1.SelectedIndex = -1
End Sub

When it does not for you, reply than I past in the test I made.

Cor
Nov 21 '05 #11
On Sat, 14 Aug 2004 15:31:12 +0200, "Cor Ligthert" <no**********@planet.nl>
wrote:
Steve,

This works without any problem for me.

Private Sub Form2_Activated(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.ListBox1.SelectedIndex = -1
End Sub


Thanks Cor. That works :) Using clearselected works there too.

thanks again for your help
Steve

Nov 21 '05 #12
Herfried,

I was assuming that as well in my first message.
However is that not that combobox textbox part?

:-)

Cor
Nov 21 '05 #13
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I was assuming that as well in my first message.
However is that not that combobox textbox part?


Maybe it's a bug in the underlying 'ListControl' implementation that is
used by both, comboboxes and listboxes.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.