StrataFrame Forum

Non Editable Combobox

http://forum.strataframe.net/Topic28670.aspx

By Diu King,Tiong - 10/12/2010

Hi all,

Textbox got the property's readonly set to True then the textbox become non editable.
How if i want make my combobox non editable?
I did tried set it's DropDownStyle = ComboBoxStyle.DropDownList but it cannot work.


Please advice.
By Trent L. Taylor - 10/13/2010

I assume that the Enabled property does not meet your needs?  If not, is it because you just want a read-only look while not being editable?
By Diu King,Tiong - 10/13/2010

Hi Trent,

Yes, I just want combobox a read-only look while not being editable. I did tried on enabled property but it not work.


Please advice
By Greg McGuffey - 10/13/2010

Just to be clear, you want to select the text in the box and also be able to drop it down?
By Diu King,Tiong - 10/13/2010

Hi Greg,

I want my combobox just for display record only (read-only). Users are not allow to input any text and not able to drop it down.


regards
By Greg McGuffey - 10/13/2010

A better choice might be to not use a combo, but rather to use a text box. There are several options, from easy/ugly to elegant with some work BigGrin

- Hide the combo, drop a text box on, and in the navigated event of the form, set the text boxes text to that of the Text of the combo.
- Add a custom bindable field to the BO for the text shown in the combo (I can help you with this if you need it), then bind this custom field to the textbox on the form.
- Create a custom control that can be filled like a combo, but only shows the text of the bound ID.  This would be some work, but very cool. BigGrin
By Diu King,Tiong - 10/13/2010

Hi Greg,

How if i only want my combobox to be read-only when my menutoolstrip's itemclicked = Edit?
But when menutoolstrip's itemclicked is not equal to Edit, i still allow user to choose item at combobox.


regards
By Greg McGuffey - 10/13/2010

Ah, didn't understand that part. Well, then you need a combo. BigGrin 

I'm not quite sure how what you want is different than what a combobox normally does. Normally, if you allow the BO to manage the UI, it is disabled until the BO is edited. When disabled it shows whatever value is currently selected. When edited, the drop down now works and the user can enter values into the control. How is what you want different than this?
By Diu King,Tiong - 10/13/2010

Hi Greg,

I want is when BO is edited, combobox in disabled mode.
Combobox just will enabled and editable when BO in new row record added.


For example:

   Private Sub MaintenanceFormToolStrip1_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MaintenanceFormToolStrip1.ItemClicked
        If e.ClickedItem.Text = "Edit" Then
            Textbox25.ReadOnly = True

            *** I want combobox become disable when ItemClicked = Edit is clicked**********

            'ComboBox11.DropDownStyle = ComboBoxStyle.DropDownList
            'ComboBox12.DropDownStyle = ComboBoxStyle.DropDownList
            'ComboBox12.Enabled = False
        End If
    End Sub



Regards
By Trent L. Taylor - 10/14/2010

I have had some of the same frustrations with combos in the past as well.  At present, we inherit from the standard .NET combo and then have enhanced it.  However, one thing that is difficult for a combo is the read-only state.  By default, as you well know, there is not a read-only state like there is a textbox.  This is something that is high on my list to change in a future release.  There is one option for you, though, that could get you going today.

You can OwnerDraw the combo.  This really isn't as hard as it sounds.  I would do the following:

  1. Create your own ComboBox class
  2. Inherit from MicroFour.StrataFrame.UI.Windows.Forms.ComboBox
  3. Add a "ReadOnly" property
  4. When this property is set to True at run-time you could then OwnerDraw the combo
At present, this is really the only sure way to get it working the way that you like.  Your scenario is something that I ran into recently myself and is something that is already on the "to-do" list for a future SF release.
By Diu King,Tiong - 10/17/2010

Hi Trent,

Thanks for your help and your solution did solved my problem.