473,724 Members | 2,205 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 1619
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
3186
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
1598
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
8868
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9243
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9160
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8063
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...
0
4771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3210
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
2613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2149
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.