473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with listbox selecting an item

25 New Member
Hello,

I have a form with various controls but to simplify the problem let’s say I have 2 listboxes. The selection in listbox1 controls RowSource of the listbox2. For example lstCars contains car models, if I select car model X then lstColors should give me available colors for that particular model. The problem is if I select car model X in lstCars, I want the first color in lstColors to be selected by default.

Here is a sample code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstCars_AfterUpdate()
  2.    Call SetColors()  
  3.  
  4.    ‘problem is in the following statements:
  5.    If Me.lstColors.ListCount > 0 And Me.lstColors.ItemsSelected.count < 1 then
  6.        Me.lstColors.Selected(1) = True
  7.    End If
  8. End Sub
  9.  
  10. ‘function to change rowsource of lstColors to correspond to selection in lstCars
  11. SetColors()
  12.    Me.lstColors.RowSource = “Select Color From [tbl Cars] Where Model = ‘”   &    me.lstCars.column(0) & “’”
  13. End sub
After the code is executed. Item in lstColors locks up and no more changes can be done in that listbox. I think sub "lstCars_AfterU pdate" is being called if I click on any item in lstColors, always selecting the first item.
I’m not sure what is going wrong but obviously I’m missing something, Please help.
Feb 7 '08 #1
3 1614
NeoPa
32,569 Recognized Expert Moderator MVP
I can't see a problem.
Try using the debugging facilities (Debugging in VBA) to identify whereabouts your code is differing from what you expect it to do.
Feb 7 '08 #2
is49460
25 New Member
I've changed event from AfterUpdate to BeforeUpdate and it appears to work fine... I need to look more into it. I dont have an expaination why, but that change solved the problem.
Feb 8 '08 #3
NeoPa
32,569 Recognized Expert Moderator MVP
Well, good for you.

I must admit, I can't see why that would have any effect.
I'm glad it's working for you anyway :)
Feb 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3183
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView. Here's my question Which should fire first, the DataTable's RowChanged/CellChanged event or...
0
311
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView. Here's my question Which should fire first, the DataTable's RowChanged/CellChanged event or...
0
266
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView. Here's my question Which should fire first, the DataTable's RowChanged/CellChanged event or...
2
1597
archulu
by: archulu | last post by:
hai this archulu Any one help to me, in my project i am using Domapi script for creating Listbox. the main problem is i am creating one button, when that button clicking Listbox(Domapi) was opend. after i am selecting any item in that list of Listbox, that selected item was store in to some variable. upto this my program ok. Now my Main Problem is after storing the value in to variable that Listbox was want to hide. plz any one help to me...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.