I've stumbled upon a phenomenon which I can't explain myself and I'm interested in why it is happening. I hope someone can explain me the reason and also how to get rid of this phenomenon:
I have created a few pages for the application and then a search page. So far so good. Whenever I tried to click on the combobox itself it opened normally, but as soon as I released the mousebutton it closed again. Except when I moved the mouse outside of the combobox area and THEN released it. The only thing out of the ordinary I saw there was that the focus was reset automatically to the last text-field before the combobox.
The combobox itself was a normal html combobox while the textbox itself was created with Html.TextBox("search") I also tried to change the namings in case I overlooked something in javascript but no changes.
I then tried the following:
#Html.TextBox("search")
Kategorie #Html.DevExpress().ComboBox(
settings => {
settings.Name = "PrductCategory";
settings.ControlStyle.CssClass = "select";
settings.Width = 300;
settings.SelectedIndex = 0;
settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDown;
settings.Properties.IncrementalFilteringMode = DevExpress.Web.ASPxEditors.IncrementalFilteringMode.Contains;
settings.Properties.TextField = "Name";
settings.Properties.DisplayFormatInEditMode = false;
settings.Properties.Native = false;
settings.Properties.TextFormatString = "{0}";
settings.Properties.DisplayFormatString = "{0}";
settings.Properties.ValueField = "Id";
settings.Properties.ValueType = typeof(int);
}
).BindList(Categories).GetHtml()
This behaved as it should have the whole time (although the combobox was horribly formated. As I did not find out how to format it to look like a "normal html" combobox I decided to try the native mode but more to that below). When I set the native mode to true, the same phenomenon happened again (with false again it behaved normal).
After a few hours of looking through tutorials and docs I'm still at a complete loss (especially as I didn't find any setfocus commands being used).
So my question is:
Does anyone have any clue as to why that could happen and how to stop this phenomenon from happening?
Tnx
Remarks:
When in native mode and I switch via tab onto the combobox I can go through the list as normal (with the arrow keys), but I still can't open the combobox as it again closes automatically and the focus is reset onto the textbox ("search") as in all other cases (aside from native=false).
When native mode is set to false and I click on the combobox, then the focus is lost (and set to the text field before the combobox [and it's textfield] for under 1 second and then set to the combobox while the combobox does NOT close).
Thomas,
It sounds like some of the DevExpress settings you're using to initialize the ComboBox may be causing strange behavior in the browser. Could you include a copy of what the rendered control looks like from the browser source?
It might be worth removing some of the optional settings such as IncrementalFilteringMode to see if that is causing a problem.
Related
I can't get a form to remain on top, in .net
I have checked How to make form always on top in Application and the answer there mentions form1.TopLevel = true; and I've checked How to make a window always stay on top in .Net? and it says Form.ActiveForm.TopMost so i've tried Form.ActiveForm.TopMost = true; and this.TopMost = true;
private void Form1_Load(object sender, EventArgs e)
{
this.TopLevel = true; //default anyway
Form.ActiveForm.TopMost = true;
this.TopMost = true;
}
But as you can see, a notepad window or any window can cover it.
Added
I have tried every suggestion made so far.
In response to Han's advice, "Of all the possible places to set TopMost property, the Load event is the worst. It should be set in the constructor, so the window gets created top-most right away. Or it should be set after it is visible, so after the Load event. Use the constructor. ". I tried putting those lines in the constructor.
public Form1()
{
InitializeComponent();
this.TopLevel = true; //default anyway
//Form.ActiveForm.TopMost = true; (commented to prevent a System.InvalidOperationException, presumably the form isn't yet active at this stage)
this.TopMost = true;
}
And the the other two suggestions, from others-
I tried setting the Form's TopMost field in the designer to True.
And running the EXE directly rather than just clicking play in visual studio.
Same issue.
And if you find that hard to believe, i've taken a 1min video here showing just that. https://screencast-o-matic.com/watch/cbXXrw2oTN
A potentially useful comment was mentioned..
Steve comments - "OK something definitively odd is happening here. I have tried to create a simple topmost form using linqpad and at the first run I get your same behavior. At the second run though everything works as expected."
A workaround, is this, following on from Han's point to put not put it in Load. Load is indeed too early. I've been finding that (at least on the system with the issue), The Constructor is also too early. I find that putting it in the Shown event, works.
One possible solution to this, is to run this patch, https://support.microsoft.com/en-us/help/2587473/topmost-windows-are-not-always-in-the-topmost-position-in-windows-7-or But be warned, if you want to uninstall it, I have some doubts whether it uninstalls correctly. And it's also not clear to me whether the patch is working or working sporadically. It likely works but it's hard for me to tell.
One commenter thought it's just my system, though that's not the case, as Steve ran into the same issue the first time he ran it. I find it may be most prone to happen after windows restarts, So, the program is running very fresh. But I find that putting that code in the Shown event, is fine and the form stays on top.
I tried instead of TopMost=true, using SetWindowPos, to set the window on top, I tried it fairly early like in the constructor, and late, like in the Shown event or on a button click, and I found it was fine in the Shown event or on a button click. So the issue was related to the TopMost=true line, or SetWindowPos line, firing too early, prior to the window it is setting appearing.
When calling SetWindowPos later one can use either this.Handle or GetForegroundWindow(), the former is easier as it's native. When calling it earlier one must use this.Handle. And using this.TopMost=true avoids all winAPI calls completely.
So in short, you could try the patch, though note that it might not uninstall right.. Or you can try the workaround of putting this.TopMost=true in the Shown event of the form.
I'm a university student therefore I'm not sure on everything to do with writing code. If you could provide hints or a bit of help. I have hidden the listbox via the designer. I've tried listbox1.Show under next button event handler. I've tried looking around on the web but I'm getting no where.
Now answered. Thank you
The solution depends on how you've hidden your listbox. If you did set visible property to false, just use listbox1.Visible = true;.
If you used ' Send to back' to hide it behind another control, you can use listbox1.BringToFront(); to set it into the foreground.
See https://msdn.microsoft.com/en-gb/library/system.windows.forms.control.visible.aspx and https://msdn.microsoft.com/en-gb/library/system.windows.forms.control.bringtofront.aspx
Inside Button_Click Event write:
listbox1.Visible = true;
In my opinion, the best way to show/hide controls (in WPF) is to collapse them. This allows the rest of the controls to behave as if the collapsed control does not even exists, until it is made visible, of course.
This would be done like so:
control1.Visibility = Visibility.Collapsed;
control1.Visibility = Visibility.Visible;
If you are using WinForms, controls will not have a collapse option, and the correct way would be as Almansour has said.
I want to write a coded UI test like "Some WPF control when some condition should not be visible". How do I assert "is not visible"?
To reproduce the issue:
create new WPF app
add nothing but one big named button into the main window
go to CUIT editor and recognize the button
without closing the CUIT editor close the WPF app
add Visibility="Hidden" to the button
restart the app
select the button in the CUIT editor and press "refresh" button
NOTE: the properties of the hidden button are exactly the same as properties of visible button!
There's no way to assert that the button is hidden!
Additionally:
I would be glad to hear about workarounds you're using. After all what I need is to write the test, not figure out CUITs
I am aware that I can compare screenshots
Interestingly if you try to do stuff with the hidden button the CUIT will throw. It implies that the CUIT knows when a button is hidden.
Interestingly if Visibility="Collapsed" instead of "Hidden" CUIT will recognize it by reporting Width = Height = -1. That doesn't help with collapsed buttons though :(
I've found the best way to work around the IsVisible limitation is to use the TryGetClickablePoint(out System.Drawing.Point) method of the UITestControl object. This method will return a Boolean value. So, for example, if you have a WpfButton:
WpfButton mine = new WpfButton(parent);
mine.SearchProperties["id"] = "id";
Point toString;
bool result = mine.TryGetClickablePoint(out toString);
Assert.IsTrue(result, "My Assertion here.");
That has worked more often than not. To handle collapsed or expanded, though, is there some property of the object that changes based on its state? For example, if the class is class="myobject expanded", you could easily assert based onmine.GetProperty("Class").ToString().Contains("expanded"); as a Boolean value.
Try to use GetProperty method:
WpfButton myButton = new WpfButton();
if(myButton.GetProperty("Enabled").Equals(true))
{
... CODE
}
I have an AutoCompleteBox binded to an ObservableCollection ItemsSource which I filter on my own by querying entities from a domainservice.
I used the scenario of populating from a webservice call from the blog of Jeff Wilcox, by setting the PopulatingEventArgs.Cancel to True, and when my collection is ready, I call PopulateComplete() on the ACB.
My goal is to reopen the dropdown on mouseover (or click) but without reloading again all the data from the web. I found a question on stackoverflow where the answer was to set IsDropDownOpen to True. But in this case, the ACB population starts again, and another call goes to the webservice.
Of course, when the user starts typing, the filtering should be done again.
(for ex. you type "ric" and the box suggests "rice" and "ricin", you select rice, but you change your mind and want to select another one from the same collection, lets say "ricin". In this case you already have the suggestions containing "ric" in memory, no need to load them again..)
I found an alternative way in which instead of setting IsDropDownOpen, I just simply call the PopulateComplete() method. This does exactly the same thing that I want, but with a little fail: after my ACB loses focus, the dropdown is not opened again on mouseover liek it should. Even when I click back into the acb textbox.
So is there a fix for this, or does someone know why the PopulateComplete() only reopens the dropdown when the ACB has focus for the first time? Or this was only my luck that calling this method reopened the dropdown and the IsDropDownOpen property should be used instead (afaik this would be only possible with some flags indicating that its a fake populating event triggered by my mouseover and after PopulatingEventArgs.Cancel i should call immediately PopulateComplete. but i dont get it, if this may work (haven't tried yet), why not when calling simply the PopulateComplete)?
Well, I tried the IsDropDownOpen with a testing bit, and almost worked:
private void FoodBox_MouseEnter(object sender, MouseEventArgs e)
{
//FoodBox.PopulateComplete(); not working after acb loses focus...
testbit = true;
FoodBox.IsDropDownOpen = true;
}
Here's the overloaded Populating method (no need for setting ItemsSource explicit because its bound to an ObservableCollection):
public void FoodBox_Populating(object sender, PopulatingEventArgs e)
{
e.Cancel = true;
if (!testbit)
{
VM.LoadFoodSuggestions(FoodBox.SearchText);
}
else
{
testbit = false;
FoodBox.PopulateComplete();
}
}
This works good so far, execpt that the search does not start because when (for the first time) you mouseover and select the acb, it sets the testbit to true.
So I added another event handler that takes care of setting the testbit to false every time the user inputs text on the keyboard, ensuring that the suggestions are regenerated/reloaded after SearchText is modified by the user, but not when you select an item from the dropdown:
private void FoodBox_TextChanged(object sender, RoutedEventArgs e)
{
testbit = false;
}
I still don't know why calling PopulateComplete() isn't enough without setting the IsDropDownOpen to Ture, and setting that to true, also delays the dropdown opening approximately with the time specified in the MinimumPopulateDelay, but at least it gives me the functionality I wanted. (Maybe digging into the source of acb would answer this mistery)
Maybe this functionality implemented in the basic acb would be helpful in a future release of the control.
Simplifying
I have a text box and a button
The button just create an messagebox with the text from the textbox.
But i change the value of the textbox, the new value apears (Ex: Type 123) but the message box does not show the value.
If i try to use the value in the programming (get the value by textbox1.text) the variable has nothing ( textbox1.text = "") but i can still see what i typed in the form.
Anyone has any clue?
Your button's click event handler should look something like this
private void button_Click(object sender, EventArgs e)
{
MessageBox.Show(textBox.Text);
}
I suspect you already have code similar to this and that at some point the textbox is cleared or otherwise set to String.Emppty but without seeing actual code it is difficult to help you
When/where did you check the value of textBox1.Text? If you're checking it in the constructor, Form1_Load, or anything else that occurs before you'll have typed text, you will get an empty value.
To properly check the value of textBox1.Text, you should set what's called a breakpoint on the line that calls MessageBox.Show(textBox1.Text). To do this, click in the grey area of the source editor (it's on the far left) on the line containing MessageBox.Show(..). A red circle will appear and your code should be highlighted. When you run your application and click on your button, your application should pause and Visual Studio will highlight that line and from here you can hover over "textBox1.Text" in the MessageBox.Show() line and it should show you the current value.
If your application is as simple as a form, a textbox, and your button1_Clicked event handling code, this should work no problem. If it is not this simple, then you need to look for anything that sets the value of the textBox in your code and make sure it isn't passing any blank values by using breakpoints.
To solve this properly, though, we really need more information.
Thanks Eric and Crippledsmurf. As both of you said, its hard to help without the code.
The problem I found is that when calling the form, I send some objects by reference, so I can track them down and I found that when (don't ask me why it happens that way, I'm still working on it) the construtor is called he make an new component, so the component in the interface no longer represents the one pointed by the variable "textbox1" (Yes Crash893, I haven't mispelled the name).
I found that I was making some mess with the references, and probably that was causing the problem. I fixed the problem by changing the actions performed by references for delegates and events, but I couldn't track down the exactly source of the problem.
Thanks, again, everyone for the insights.