开发者

Combobox background color while not enabled

I have a combobox that I have Enabled = false. When that is the case it causes it to shade to a grey. I was wondering if there was a way I could keep the checkbox background color as cornsilk while it is not Enabled?

The situation is that I have a form that I will refresh with data when an item is selected. If the user selects to edit the record I enable the form to accept changes and since it is mainly textboxes I just change the readonly property of those. But the combobox looks开发者_JAVA技巧 different so I want to see what I can do to make it stay the same like the rest of the form...

Any ideas?


I would simply hide it with a TextBox over it and setting its Visible property to false. Then, you your user click the Edit button, you hide your TextBox and show your ComboBox with its Visible property set to true.

Perhaps you wish to update your TextBox.Text property by setting its value to the ComboBox.SelectedItem property value on the SelectedItemChanged() event handler.

Let's suppose the following:

ComboBox cb = new ComboBox();
// Position, size and other properties are set through design.
cb.SelectedIndex = 0; // Forces selection of first item for demo purposes.

TextBox tb = new TextBox();
tb.Size = cb.Size;
tb.Position = cb.Position;
tb.Text = cb.SelectedItem.ToString();
tb.Visible = true;
tb.Readonly = true;

cb.Visible = false;

Then, clicking the Edit button:

private void EditButton_Click(...) {
    tb.Visible = false;
    cb.Visible = true;
}

And make your TextBox.Text property value follow your SelectedItem:

private void ComboBox_SelectedIndexChanged(...) {
    tb.Text = cb.SelectedItem.ToString;
}

And you would only do the reverse of your EditButton_Click() event handler to bring back your form in read-only mode.


You may consider using Jquery UI or other plugins if aesthetics of form are important. You can control entire look and feel with the CSS.

Hiding combobox with textbox is a possibility as suggested by Will but then you will have to use absolute width for the dropdown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜