Hi,
Say I have a list box. I also created a control on a form bound to that
list box. When I click different rows in the listbox the control
changes the ID of the row depending on what I click.
One thing I'm doing is setting the .selected(i) property of the list
box to true. On the screen I see that a different row gets hillighted,
but the bound control on the form is showing the wrong value?
So changing what is selected with code did not turn out to be the same
as cliking on the list box? Does this make any sense?
Lyle Fairfield - 17 Dec 2005 22:42 GMT
Absolutely.
Perhaps you could explain "created a control on a form bound to that
list box."
as this might not mean the same thing to all of us
and/or
posting any code that you may be using to effect this binding would
help.
ken - 17 Dec 2005 22:57 GMT
Hi,
Thanks for your reply.
Um..The control I'm refering to is a text box. Its Control Source is
=[LBox].Value
Here is how I change the selected property of the list box LBox:
For i = 0 To LBox.ListCount() - 1
If LBox.Column(0, i) = Me.pkItem Then
LBox.Selected(i) = True 'this changes the highlited value in the
list box
End If
Next
By the way this is a single select list box..can only select one thing.
Anyhow after that loop I see a change in the highlited row. So before I
had row 5(LBox.Value = 5) selected, after I had row 3 (LBox.Value = 3)
selected.
However my textbox tells me that I still have Row 5 (LBox.Value = 5)
selected?
Lyle Fairfield - 17 Dec 2005 23:50 GMT
Sometimes code like this doesn't run when it is in an event procedure.
We think the event has been fired because we have done something in
code. But it is not fired when do something in code.
To know if this might be a problem causing the behaviour you describe,
we need to know if this code lives in an event procedure, and if so,
which one.
ken - 18 Dec 2005 00:03 GMT
Its in the OnClick event for a command button. The function of the
command button is to 1. Change the selection in the List Box, and 2. To
refresh another Listbox in the form. Since the second list box depends
on the selected value of the first listbox, it would be nice for the
actual value of the first listbox to be updated when you change the
.selected property.
Thank you.
Mike Preston - 18 Dec 2005 00:19 GMT
>Hi,
>Thanks for your reply.
[quoted text clipped - 6 lines]
> If LBox.Column(0, i) = Me.pkItem Then
> LBox.Selected(i) = True 'this changes the highlited value in the
Insert here:
LBox.Value = LBox.Column(0, i)
mike
>list box
> End If
[quoted text clipped - 7 lines]
>However my textbox tells me that I still have Row 5 (LBox.Value = 5)
>selected?
ken - 18 Dec 2005 00:27 GMT
salad - 17 Dec 2005 22:55 GMT
> Hi,
> Say I have a list box. I also created a control on a form bound to that
[quoted text clipped - 7 lines]
> So changing what is selected with code did not turn out to be the same
> as cliking on the list box? Does this make any sense?
The mouse click should set your Selected property. One thing you might
want to consider is if you have ColumnHeading set to true. That offsets
you row count by 1.
ken - 17 Dec 2005 22:58 GMT
No that's not the issue...no offset. I'm talking about where a
different item gets selected, but the LBox.Value is still the old one...
Mike Preston - 17 Dec 2005 23:21 GMT
>Hi,
>Say I have a list box. I also created a control on a form bound to that
[quoted text clipped - 7 lines]
>So changing what is selected with code did not turn out to be the same
>as cliking on the list box? Does this make any sense?
Lyle is being particularly kind.
But, translating with a crystal ball, I guess that you have a bound
multi-select listbox. The list box can have multiple items selected.
The field that the listbox is bound to can only store one result.
Hence, a bound multi-select listbox is destined for confusion.
I'm not even sure why Access allows multi-select list boxes to be
bound. Endless confusion results.
You will need to walk the items of the listbox to determine whether
each is selected and then use the results accordingly, probably by
storing the value of each selected item somehow.
But I am just guessing.
mike
ken - 17 Dec 2005 23:39 GMT
Actually I have a single select list box...not multiselect!