473,395 Members | 1,464 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,395 software developers and data experts.

How to make a combobox make certain items not be selectable?

TheSmileyCoder
2,322 Expert Mod 2GB
I have a combobox linked by SQL to a table. The table has standard Primary Key (Autonumber) and text field.

There are 3 records:
Expand|Select|Wrap|Line Numbers
  1. KEY_DocType tx_DocType
  2. 1           RMT Document
  3. 2           Review Document
  4. 3           Reference Document
  5.  
I would like it to be so that, IF the document type is allready set to RMT document, that the user can view the text (RMT document) in the combobox, but I want it so that when the user clicks the dropdown, that the user can only select Review Document or Reference Document, I.e. that the RMT document is simply not presented in the dropdown list.

I know I can handle this through AfterUpdate, but I was hoping for a more elegant solution.
Mar 4 '11 #1
10 6684
jimatqsi
1,271 Expert 1GB
I think it will work if you just add the appropriate Where clause to the criteria of the rowsource of the combo box. The value of the bound data item will show in the text box but when you click to browse other entries you will see what the rowsource returns.

If the bound value is not "RMT", are they allowed to choose RMT? If that is the case then you will have to dynamically build your rowsource string based on the value of the bound data item, if ="RMT" then the rowsource = one thing, if <>"RMT" then the rowsource =something else.

Jim
Mar 5 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
I have allready tried just setting the where clause to exclude some records simply gives a blank field when i use those values (Since im displaying the second column of the table, the first column being the primary key)

I did find a solution myself. I place a textbox directly above the combobox, in such a way that only the dropdown of the combobox is visible, the controlsource of which is pulled into the recordsource of the form, by a left join. I disable the textbox completely, and use the forms Current event to decide whether or not to enable the combobox. Its a "hack" but it works.
Mar 6 '11 #3
reginaldmerritt
201 100+
Thats a good way around it SmileyCoder. I have had a similar issue before.

You could also set the row source for the ComboBox in Form_Lode routine to the Table allowing any items to be visible. Then set the row source to the query in the ComboBox_Click routine.

Only issue there is that if a user decides to change the ComboBox value they won't be able to change it back to its original value.
Mar 9 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
I did consider your approach but it requires the combobox to be requeried each time the user clicks on it, which is the reason why I choose the other approach. However, thank you for your input. I can only get wiser!
Mar 9 '11 #5
Adam Tippelt
137 100+
What do you mean by 'more elegant solution'? Surely a more elegant solution to your 'hack' would be to base the combobox on a query (if it isn't already), and set the criteria to:

Expand|Select|Wrap|Line Numbers
  1. <> [ComboboxName].[value]
It would require the combobox to be requeried after update, but you can make a new selection in the combo box which is then filtered out of the drop down list on selection, and the old value is put back in the list.

EDIT: What is wrong with requerying it when the user clicks?
Mar 9 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Your implementation would merely mean that the user cannot reselect a value which is allready selected.

While I could requery the combobox I would have to query it both when the user clicks the dropdown as well as when the user moves to a new record (otherwise the RMT document value would not be shown).

There is nothing wrong with doing a requery if your database is local or on a fast network. However if you are on slow network, I dont want to give the user a 0.3sec delay on opening the dropdown.
Mar 9 '11 #7
Adam Tippelt
137 100+
I thought that was what you were trying to do - "I.e. that the RMT document is simply not presented in the dropdown list." Perhaps I misinterpreted what you meant.
Mar 9 '11 #8
TheSmileyCoder
2,322 Expert Mod 2GB
I have 3 types of documents. If the document is a RMT Document is metadata is created and maintained automatically through my application. The other 2 types of documents are created outside the company and we manually enter metadata about them. Since a RMT document will never need to be manually entered, I dont want to display that in my dropdown.

If I filter it out, it wont be visible in the dropdown, since its a 2 column dropdown, with the first column being the Primary key, and has Width=0 (so its hidden).

Yes I could probably change the recordsource on click, but what about if a user tabs into the field? I thank you for your input, but I dont see how its better then my hack :P
Mar 9 '11 #9
Adam Tippelt
137 100+
Ah well...you can't blame a guy for trying. :P
Mar 9 '11 #10
NeoPa
32,556 Expert Mod 16PB
As you say Smiley, this is not a natural way of behaving for a ComboBox, and I for one, can't think there is a way to do it naturally.

That said, if we're looking at hacks, what about simply setting the .ValidationRule property to disallow selection of that record? I can't see a way of both allowing the ComboBox record to reflect that value ("RMT Document") for those form records with it already selected, as well as disallowing it for all others.
Mar 10 '11 #11

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

Similar topics

0
by: dr.p.dietz | last post by:
Hello, i've a extended combobox with own properties based on normal combobox. I create the combobox on runtime as myownControls.ownCombobox and assign datasource, displaymember, valuemember. ...
6
by: Brett Miller | last post by:
Hi, I need to change the colour of certain items in a listbox depending on criteria I receive from my dataset? How would this be accomplished? Thanks in advance... BM
5
by: Carrie | last post by:
Good Morning, I have a combobox whose list is bound to DataSet1.Sales Growth Options.Sales Growth. The data is double and I would like it displayed as a percentage. I have tried two things: ...
1
by: Nick Zdunic | last post by:
I have a grid view with a column of dropdowns. Some of the items displayed in this dropdown need to be displayed in bold. Other are left as is. Is the GridView the best control for this or is...
1
by: Gian Paolo | last post by:
hi all i'm looking for a way to add 2 items in a combobox in the same line and hide one. i'm working on the code above but it returns me only the last value i entered and i do not know why.... ...
0
by: marcobx | last post by:
I have a ComboBox and a List of objects to popolate items. I use the DataSource property and not the List collection: List<foolst = new List<foo>; //add elements into the list //......
2
by: gleadams | last post by:
I have databound a Windows form ComboBox control to a DataSource and DataMember and it is properly showing the data as I navigate through the records. My question concerns the choices in the...
2
by: Shrini76 | last post by:
Hi, I want to override certain behaviors of the combo box. So, I created a base class derived from ComboBox. What I want to achieve is to make the combobox drop up (that means when user tried to...
3
by: beemomo | last post by:
I have two tables - 'Client' and 'Company', and two forms, 'Client' and 'Company', the relationship between two table is 1:many where a company can have one or more client but each of the client...
0
by: RS | last post by:
I have a datagridviewcomboboxcolumn bound to a Funding source table in database. With time these funding sources may be inactiveted (inactive flag is set in the table). So when you open up a new...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.