 |
|
 |
You must also stop the user from pasting into the control by intercepting the right-mouse click event.
|
|
|
|
 |
|
 |
I can see that the download does not include at least one of the fixes described in the comments. Is there a place to get the latest code?
Thanks.
|
|
|
|
 |
|
 |
I'm new to C# so maybe I'm missing something, but I solved this problem by just adding a keypress event handler. It seems to work fine for me.
private void unitComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.KeyChar = (char)0x00;
}
-Jeff
|
|
|
|
 |
|
 |
This is what I needed. Thanks a lot !!
Jose Luis.
|
|
|
|
 |
|
 |
Hi!
You have in your "Todo" 'Remove the White Border'. Well, I don't get it done? So how to remove that white Border as I want my ReadOnlyComboBox look like a Label?
thanks for help
|
|
|
|
 |
|
|
 |
|
 |
I tried your version, Claudio, because I liked the idea of swapping in the read only text box. However, it does not work well with a TableFlowLayoutPanel. The extra control (the text box) gets added into its own cell upon "_textBox.Parent = ...". Unless there is a way to fix that problem, the combo needs to work by itself (or be incompatible with layout panels).
|
|
|
|
 |
|
 |
After I saw this article, I thought there might be a much easier way to accomplish this goal: set the Enabled property to false and the fore and back colors to their appropriate read only colors. If it worked, it would be really simple and the technique would work for any control. Unfortunately, the ComboBox ignores the fore and back colors when the ComboBox is disabled. Here's the code I tried: Private _readOnly As Boolean Private _savedEnabled As Boolean Private _savedBackColor As Color Private _savedForeColor As Color Public Property [ReadOnly]() As Boolean Get Return _readOnly End Get Set(ByVal Value As Boolean) 'if the property value changed If Value <> _readOnly Then If Value Then _savedEnabled = Me.Enabled _savedBackColor = Me.BackColor _savedForeColor = Me.ForeColor Me.Enabled = False Me.BackColor = SystemColors.Control Me.ForeColor = SystemColors.WindowText Else Me.Enabled = _savedEnabled Me.BackColor = _savedBackColor Me.ForeColor = _savedForeColor End If _readOnly = Value End If End Set End Property It's too bad this doesn't work. I wonder if there's anyway to force the fore and back colors when the ComboBox is disabled.
|
|
|
|
 |
|
 |
I seem to have discovered an issue. Hoping you can help me solve it. In the native ComboBox control, when it is set for 'DropDownList' style and you press a key, it jumps to the first entry with that letter (and then the second, third, fourth, etc.. entry as you keep pressing the same button). However, with this Read Only ComboBox, I seem to be able to type data into the edit part. Is there a way to regain the Native Combobox DropDownList functionality while retaining the Read-Only-ability of this control?
Thanks.
|
|
|
|
 |
|
 |
Figured it out. I was setting the Style at Design time and it was not being picked up by the base class. If you set it at run-time, it works correctly. Alternatively, you can do some processing in the Constructor.
|
|
|
|
 |
|
 |
Do you use my last uploaded source?
In last version, data typed into the edit part is discarded if ReadOnly property is set to true, even for 'DropDownList' style and typing first character of items.
However I’m not sure that I truly understand your question.
If I can help you more I will try if you give me more details.
|
|
|
|
 |
|
 |
Yeah. I did not explain my problem very well and then I figured it out.
I was setting the ComboBoxStyle to 'DropDownList' at Design-Time. The problem occurred when the ReadOnly ComboBox was set ReadOnly = False (also at Design-Time). The Base Class (which defaults ComboBoxStyle to 'DropDown') was not picking up that I had set the Style to 'DropDownList' at Design-Time. If you set the Style to 'DropDownList' at Run-Time, it works fine. I put an extra line in the constructor to pass the Style to the base class. This fixed the problem. There is probably a more robust solution (like checking the read-only property, etc.) but this works for me.
Thank you for your response.
|
|
|
|
 |
|
 |
You can also use this
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
|
|
 |
|
 |
Yes but this is not read only . This restricts the user to select only one value from a list o values. Read only restricts the user to change actual selected value.
|
|
|
|
 |
|
 |
Nice Control. It is just what my program needed. I don't think some people understand the purpose of this control (i.e. Giving people the ability to easily read the value in the ComboBox but not change the value), but it is perfect for what I'm doing.
Thank you again.
|
|
|
|
 |
|
 |
Refreshing a DropDownList from a selected DropDownList
I have a Problem in a form, I have 3 DropDownList I already connect them to the DataBase but I want't them to do a secuence, example, if I select in the first one the letter F, I want in the second to appear only Words with the letter F, and if I select the word Ford, in the third one appear only ford car models.
I need some help to do this.........
Thanks.....
Paco
|
|
|
|
 |
|
 |
Hi, good article but I have one remark. If this control must be complete,
you must foresee all situations of binding. For example if you'r combo is bound by "Text" property to some datasource (for example datatable or dataview or ...) it will reflect on the data in datasource.
Boyan Botev - FreeStyle557
|
|
|
|
 |
|
 |
still the RMB menu option cut is enabled which allows you to delete tht contents which makes this not readonly
|
|
|
|
 |
|
 |
You are absolutely right;) … but if you’re look at my previous replies you’ll see that I specify the need to override right click event to block menu or display custom menu.
Anyway, next days, when I’ll have enough free time I will update my article with full functional code .
|
|
|
|
 |
|
 |
Why block the RMB menu; isn't there a way just to block the Cut & Undo options.
|
|
|
|
 |
|
 |
Why block the RMB menu; isn't there a way just to block the Cut & Undo options.
|
|
|
|
 |
|
 |
if you change it to DropDownList you will get the same result if the comboBox had a ReadOnly property... or is it?
|
|
|
|
 |
|
 |
No, DropDownList it's not the same as ReadOnly because you can change actual value by selecting from the list.
ReadOnly means that you can't change selected value.
|
|
|
|
 |
|
 |
using System;
using System.ComponentModel;
namespace YControls
{
///
/// ReadOnly ComboBox.
/// DropDownList can open, but selection can't be changed.
///
public class ReadOnlyCombo : System.Windows.Forms.ComboBox
{
private bool readOnly;
[Description("DropDownList can open, but selection can't be changed.")]
[Category("Behavior")]
[DefaultValue(false)]
public bool ReadOnly
{
get { return readOnly; }
set { readOnly = value;}
}
private int selectedIndex;
protected override void OnSelectedIndexChanged(System.EventArgs e)
{
if(this.ReadOnly)
SelectedIndex = selectedIndex;
else
{
base.OnSelectedIndexChanged (e);
selectedIndex = SelectedIndex;
}
}
}
}
|
|
|
|
 |
|
 |
The combo box still drops down when pressing F4 and changes on PageDown/PageUp.
OnKeyDown has to be changed as followed
protected override void OnKeyDown(KeyEventArgs e) {
if (this.ReadOnly
&& ( e.KeyCode == Keys.Up
|| e.KeyCode == Keys.Down
|| e.KeyCode == Keys.Delete
|| e.KeyCode == Keys.F4
|| e.KeyCode == Keys.PageDown
|| e.KeyCode == Keys.PageUp)) {
e.Handled = true;
} else {
base.OnKeyDown (e);
}
}
|
|
|
|
 |