Combo Box On Windows Form

SANCHIT SHARMA

Active member
Joined
Jul 15, 2005
Messages
38
Programming Experience
10+
On my form at some places i want to disable combobox. To achive this we set the ENABLED Propert = FALSE. This action turns the control to grey..

But i want this in a different way.It should be displayed as it is displayed in normal form. But neither i should be able to make any modification in it nor be able to move control over it.

By default no such property is available.

I tried...
</IMG>CanFocus Gets a value indicating whether the control can receive focus.(Inherited from Control.)
pubproperty.gif
</IMG>CanSelect Gets a value indicating whether the control can be selected.(Inherited from Control.)


ComboBox.ObjectCollection.IsReadOnly Property


But all efforts went in vein..



Please help. Early response will be highly appreciated


Regards
 
i'm not sure how to achieve this with a combobox, i know with textbox's once you set the ReadOnly property to True all you need to do is change the BackColor back to SystemColors.Window and it looks normal again

i just tried this with the combobox and it doesnt work that way
 
do you mean, you just want to set the control enable to false and want the control to appear such as normal (still enabled!?)

if so just change the back color of the control to white.
 
You can't that with a ComboBox unless you want to draw it yourself. The fisual cues are supposed to let the user know that the ComboBox is disabled. If a ComboBox looks enabled but nothing happens when I click it I'm going to think that the program is broken. If you really want to do what you're asking for, which I advise against, then just hide the ComboBox and display a TextBox. You can make it ReadOnly and change the BackColor if you want. That way there's no arroe button to indicate to the user that they can click it to see a list.
 
Thanks for you suggestions. In MS Access there is a property

Enabled = false
Locked = true

this keeps the control as enabled. but dont permit user to make any modification.

Is thier any way to stop
1. Disable drop down property of a combobox
2. Mouse events can be suppressed

Regards
 
Dear Jmcihinney

One more area is there which is troubling me a lot. for example. in my datatable there are two field

aa Text width 50
bb Text Width 10

on the form aa is defined as combo box and bb as text box.

while capturing information user is free to capture information without any width limits. While saving /commiting the transaction it shows exception.

Upto now there is only one possibility at my end to control it, is to hardcode the width check at lost focus of the control and trim it to the required width. But i am not interested in hardcodeing. In case if there is any requirement in change in the size of the table column width this will force us to update the frontend.

My question is , is there any way out to retrive the width of the colum defined in a table. while defining table in dataset , does it store the size of the column , if yes then how to get that value for validation..

Regards
 
The DataTable has a Columns property that contains all the DataColumns. The DataColumn has a MaxWidth property, which you can assign to the MaxLength property of the TextBox or ComboBox.
 
What you have specified dos'nt serve my purpose. Again this method forces us to define the Max width of data that can be accomodated by the control.

We dont want to define the width in the programme

maxwidth = 50

instead of it, in
my table "AAA"
Column Type Width
aa Text 50

We should be able to capture this value from the dataset that what is the size of Column "aa" of table "aaa".

It should be able to display us 50 as a result.

suppose the size of the column is changed from 50 to 90. we will not change the value of maxlength in programme .The programme should be able to understand the modified width.

If any wayout is there pls. suggest.

Regards
 
Read again what I posted previously. It is EXACTLY what you want. You Fill the DataTable, get the MaxWidth property from the DataColumn (which has come from the database itself) and assign that value to the MaxLength of the TextBox. Voila! The user cannot enter more data than the column will allow. I repeat, this value is coming from the database each time the data is read. You aren't hard-coding anything. If you change the parameters of the column in the database then the next time you run the app this will be reflected.
 
Dear Jmcihinney

Thx for the response. In the initial phase i understood your message,also implemented the same , but didnt get the desired results. We are on VB.Net 2005

We applied it in the following way

DS_LS_ACTI = OBJ_QRY_LSACTI.SelectRowQuery("SELECT * FROM LS_ACTI ORDER BY ActiDescription", "LS_ACTI")

Dim DT_LS_ACTI As New DataTable

DT_LS_ACTI = DS_LS_ACTI.Tables("LS_ACTI")

MsgBox(DT_LS_ACTI.Columns.Item("ACTIDESCRIPTION").MaxLength.ToString())

where
DS_LS_ACTI --> dataset name

OBJ_QRY_LSACTI.SelectRowQuery("SELECT * FROM LS_ACTI ORDER BY ActiDescription", "LS_ACTI")
this line means -->execute the query and return the result in dataset

but return the result in msgbox in -1.

pls help

Best Reagards
 
If you still need a way to stop being able to edit or access a combo box:

VB.NET:
     Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
        Label1.Focus()
    End Sub

Probably not the best way to do things but it does work. As soon as the combo box gets focus it goes straight to a label.

Hope this is what you meant
 
Are you using a DataAdapter or a TableAdapter? If it's a DataAdapter you have to make sure the query returns the appropriate schema information. Set the MissingSchemaAction property to AddWithKey. If it's a TableAdapter then I don't know but I'd guess that there's an equivalent.
 
Back
Top