 |
|
 |
Thanks for your code - very cool
My suggestion is to use the inherited DroppedDown property instead of the custom IsDroppedDown to minimize behavioral/interface changes to the inherited ComboBox. I have implemented this in my code, and so far it seems to work. Originally I attempted to set DroppedDown to false expecting it to work. Is there a reason I missed as to why you did not override DroppedDown?
Here is how I implemented DroppedDown:
[Browsable(false), Description("Gets or sets a value indicating whether the combo box is displaying its drop-down portion.")] public new bool DroppedDown { get { return m_bDroppedDown; } set { if (value) ShowDropDown(); else HideDropDown(); } }
In addition, I made ShowDropDown and HideDropDown private and non-virtual, deleted the IsDroppedDown property and changed IPopupControlHost as follows:
public interface IPopupControlHost { #region Properties
bool DroppedDown { get; set; }
#endregion }
Born to code.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for your kind words!
Without having an understanding of the underlying .NET code, I wanted to avoid causing problems elsewhere. I cannot remember if I tried overriding that property or not, it has been quite a while since I originally wrote this code.
I know that I explicitly reference the base.DroppedDown property within another function in that class to hide the original standard drop down, but despite this, I think there were some scenarios where the drop down was appearing above the custom drop down.
If overriding the DroppedDown property isn't causing any problems then I totally agree, this is a much neater approach. If this is the case, then personally I think that the ShowDropDown and HideDropDown functions should be protected and virtual to allow for specialized extensions.
Many thanks, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I create a numeric panel usercontrol, I want to ask how to get caller - combobox.text? Thanks
example: this.parent.text But,it's wrong. What should I?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The simplest way is to access the combobox control with its identifier. For example:
String text = myComboBox.Text;
Or, you could make some simple changes to your user control:
public class NumericPanel : UserControl { ... YOUR STUFF ...
public ComboBox OwnerDropDown { get; set; }
public void testFunction() { if (OwnerDropDown != null) { String text = OwnerDropDown.Text; } } } And then add the following line to your construction code:
...
NumericPanel numericPanel = new NumericPanel(); numericPanel.OwnerDropDown = myComboBox;
... Let me know how you get on!
Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi!
First I want to thank you for your work. It's a really nice and helpful control.
I just started programming in C#. Now I have a question: There is no property to set the control read-only. If there is a chance to do so, would you please explain it?
Thank you very much!
siggi
modified on Wednesday, September 9, 2009 2:12 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Try adding the following property into the "CustomComboBox" class, this should solve your problem.
The "DropDownStyle" attribute was only removed because the "Simple" mode is not compatible. Thanks for the feature suggestion, it will be included in the next update.
[Category("Custom Drop-Down")] public bool ReadOnly { get { return base.DropDownStyle == ComboBoxStyle.DropDown; } set { base.DropDownStyle = value ? ComboBoxStyle.DropDownList : ComboBoxStyle.DropDown; } } Let me know how you get on.
Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thinking about it, in read-only mode the control will probably not show any text because the "DropDownList" feature requires the original drop-down.
Adding one item to the list would solve this problem, but would cause two drop-downs to appear (one on top of the other).
Again, let me know how you get on.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Nice Work.
It would be nice if your resizable dropdown honored MinimumSize.
As it stands, the constraint is enforced, but your resize logic doesn't realize it.
Another useful feature would be the ability to add buttons to the resize bar at the bottom of the drop down, to have modal behavior (e.g., cancel and close, or accept and close).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you very much for your suggestions.
I will try to incorporate the "MinimumSize" logic into the next update.
I am not sure about the idea of having a modal drop down because that is not the kind of behaviour a user would generally expect from a drop down control. In situations where a modal interface is required I would generally recommend using a dialog box perhaps with an ellipsis button: [TEXT BOX ][...]
Thanks again! Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Dear All,
Can somebody tell me is it possible to enter some value into combobox, when dropdown form is loaded.
I should do this if I want to simulate autocomplete function.
The only way I found till now is to catch keydown event from popup form and to enter catched value into combobox.
If you open simple combobox in form you can see cursor and to write into combo when dropdown is open.
Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I do not understand what you are asking.
You can handle the KeyDown event whilst the user is typing in the actual combo box control. You can also handle the DropDown event which fires then the drop down form is shown, and then DropDownClosed is fired then the drop down form is hidden.
If you want to be able to type into the drop down form (and influence the combo control) then you will need to manually implement this into your specialized drop-down form.
I hope that this is of help, let me know if you have any further questions.
Many thanks, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi - I'm trying to use your control with a TreeView, and much like a regular combobox I need to hide the dropdown when a node is selected. However calling HideDropDown() in my event handler causes the parent form to lose focus. Any way around this? Thx!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Perhaps something like the following would work?
myTreeCombo.HideDropDown(); myTreeCombo.Parent.Focus(); Let me know how you get on!
Many thanks, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I tried various combinations without success... Here's the general idea:
private TreeView treeView1 = null;
private void Form1_Load(object sender, EventArgs e) { treeView1 = new TreeView(); treeView1.Nodes.Add("Node 1"); treeView1.Nodes.Add("Node 2"); treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
customComboBox1.DropDownSizeMode = CustomComboBox.CustomComboBox.SizeMode.UseDropDownSize; customComboBox1.DropDownControl = treeView1; }
void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { customComboBox1.HideDropDown(); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Try the following, perhaps the re-focusing is being done too soon:
private TreeView treeView1 = null; private Timer timerAutoFocus = null;
private void Form1_Load(object sender, EventArgs e) { treeView1 = new TreeView(); treeView1.Nodes.Add("Node 1"); treeView1.Nodes.Add("Node 2"); treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
customComboBox1.DropDownSizeMode = CustomComboBox.CustomComboBox.SizeMode.UseDropDownSize; customComboBox1.DropDownControl = treeView1; }
private void timerAutoFocus_Tick(object sender, EventArgs e) { if (!this.Focused) { this.Focus(); timerAutoFocus.Enabled = false; } }
void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { customComboBox1.HideDropDown(); if (timerAutoFocus == null) { timerAutoFocus = new Timer(); timerAutoFocus.Interval = 10; timerAutoFocus.Tick += new EventHandler(timerAutoFocus_Tick); timerAutoFocus.Enabled = true; } }
I am unable to test the above code at this point, but I am pretty sure that something like this should do the trick.
Give it a try and let me know if it does the trick!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Much better, thanks!
Only minor change is put timerAutoFocus.Enabled = true; outside the last if statement otherwise it only works once.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Excellent, I am glad that worked for you.
Well spotted, yeah that statement should have been beneath the if statement.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
How to wrap this control with toolstrip and when i try to use usercontrol then find when RaiseDropDownEvent RaiseDropDownClosedEvent invoked then it is not that much working.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
What are you trying to do?
a) Place this control on a tool strip? b) Place a tool strip inside this control?
Can you please provide steps that I can follow to reproduce the problem relating to RaiseDropDownEvent and RaiseDropDownClosedEvent.
Possible tips:
- If you are trying to programatically show/hide the drop down part, then you should use the other two interfaces "ShowDropDown" and "HideDropDown". - If you are trying to handle an event then you should attach an event handler to either "DropDown" or "DropDownClosed".
Many thanks, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Thank you very much for your comment.
You are absolutely correct, the "DropDownClosed" event is not firing when the user clicks outside of the drop down. It does, however, fire when clicking the drop down arrow to close the popup. And it does fire when the popup is dynamically hidden.
I have made some changes to the control to fix this issue which I will upload to CodeProject soon. For the time being I have placed some instructions below. I think that this will address the problem that you mentioned above. Please make sure that you make a backup of your files prior to making the following changes:
#1 - Add the following code into the "PopupControl.cs" file:
public interface IPopupControlHost { #region Methods
void ShowDropDown();
void HideDropDown();
#endregion } #2 - Update them_dropDown_Closed function of the PopupControl class in the "PopupControl.xs" file to match the following:
private void m_dropDown_Closed(object sender, ToolStripDropDownClosedEventArgs e) { if (AutoResetWhenClosed) DisposeHost(); if (PopupControlHost != null) PopupControlHost.HideDropDown(); } #3 - Change the "CustomComboBox" class declaration in the "CustomComboBox.cs" file to the following:
public class CustomComboBox : ComboBox, IPopupControlHost Please let me know how you get on with this!
Many thanks, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I'm not a C# person and am getting a compile error on pt #2 of 3 above.
if (PopupControlHost != null) PopupControlHost.HideDropDown();
What is "PopupControlHost?"
I don't see it defined anywhere.
I look fwd to updated code being posted.
Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Ahh, sorry I forgot to mention, I have also added a new property to the "PopupControl" class in "PopupControl.cs".
Simply add the following directly beneath the "AutoResetWhenClosed" property (approx line 754):
public IPopupControlHost PopupControlHost { get; set; } Give that a try and let me know if you have any more questions. Once you have confirmed that this fixes the problem that you were experiencing I will submit an update to CodeProject.
Thanks again, Lea Hayes
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Well that elliminated the compile error but the event was still not raised.
I'd be happy to debug this for you but I don't know C#!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |