I am using the autocomplete textbox from this MSDN link.
Question:
CSWPFAutoCompleteTextBox has property "AutoSuggestionList" which I bound this to observable string collection. Each string is made of id + description. When user selects an item from dropdown, how can I override the texbox content? I want to manipulate the text box content.
This is a textbox that extends a wpf combobox to make it searchable.
When the user types in a string in the textbox, it displays matching strings as a dropdown, user selects an item and the item is displayed in the textbox.
the question is how to override the textbox contents of this control.
Without actual format of your code it is hard to answer precisely, but for example, if your strings are
string[] suggestions = {"0: Yes", "1: No", "666: whatever"}
Then you could get the number by something like
sugestedString.Substring(0, sugestedString.IndexOf(':'));
EDIT: I misunderstood the question. So if I now understands correctly, you might do it with
for(int i = 0; i < suggestions.Length; i++) {
if(suggestions[i] == selectedString) {
return i;
}
}
If you seek only a number within your list of all possible suggestions.
If you seek a number within narrowed-down suggestions, it gets somewhat more difficult.
You firstly need to note down what user has typed so-far (e.g. "Aut"). Then you need what he actually selected (e.g. "Automotive"). With those things, you can then search all your possible suggestions, count how many of them satisfies the user-typed beginning and finaly which of them is the selected one. It might look like this:
int counter=0;
for(int i = 0; i < suggestions.Length; i++) {
if( suggestions[i].StartsWith(typedString)) {
counter++;
if(suggestions[i] == selectedString) {
counter;
}
}
}
Related
I have a class with a TextField as a property. This text field is added to the stage and has a digit as a value of the text property. I also have a method, that must change this digit:
public function decrementCooldown()
{
cdText.text = (--cd.value != 0)? cd.value : "";
}
However, it changes nothing. I've modified the code that way:
public function decrementCooldown()
{
cdText.text = (--cd.value != 0)? cd.value : "";
cdText.x -= 100;
}
This caused my text field to move to the left, but its text remained the same.
Then, I've tried to trace the text before and after modifying it. The second line of the output contained the digit that I wanted to appear on screen, it was 1 less than the digit on the first line.
I wonder how to solve my problem.
Ok, this seems really strange to me, but the problem was with DropShadowFilter I had on the TextField.
I've fixed this problem by adding two lines that clear the filters array before modifying the text, then adding a DropShadowFilter again after that:
public function decrementCooldown()
{
cdText.filters = [];
cdText.text = (--cd.value != 0)? cd.value : "";
cdText.filters = [new DropShadowFilter()];
}
Seems like a bug though.
I have a web application. And I am using coded ui to write automated tests to test the application.
I have a dropdown with a text box. Which on entering values in the textbox, the values in the dropdown gets filtered based on the text entered.
If I type inside textbox like 'Admin', I will get below options like this:
And I need to capture the two options displayed.
But using IE Developer tool (F12), I am not able to capture the filtered options, because the options that are displayed do not have any unique property (like this below). And the options that are NOT displayed have a class="hidden" property
Any way to capture the elements that are displayed by applying some kind of filter like 'Select ui elements whose class != hidden'
Thanks in advance!!
HI please try below code will it works for you or not.By traversing all those controls that have class ="hidden"
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
UITestControlCollection collection = mainWindow.FindMatchingControls();
foreach (UITestControl links in collection)
{
HtmlHyperlink mylink = (HtmlHyperlink)links;
Console.WriteLine(mylink.InnerText);
}
I'm not sure there is a way to do it by search properties, but there are other approaches.
One way would be to brute force difference the collections. Find all the list items, then find the hidden ones and do a difference.
HtmlControl listControl = /* find the UL somehow */
HtmlControl listItemsSearch = new HtmlControl(listControl);
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
HtmlControl hiddenListItemsSearch = new HtmlControl(listControl);
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
You will only be able to iterate this collection one time so if you need to iterate multiple times, create a function that returns this search.
var listItemsFunc = () => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
foreach(var listItem in listItemsFunc()){
// iterate 1
}
foreach(var listItem in listItemsFunc()){
// iterate 2
}
The other way I would consider doing it would be to filter based on the controls which have a clickable point and take up space on the screen (ie, not hidden).
listItemsSearch.FindMatchingControls().Where(x => {
try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; }
});
How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.
I am trying to implement a tool that displays file names.
I would like to do this by using SetWindowText() method.
However, When I was trying to use this method in a loop,
the text is displayed in one line and it is continuously refreshed.
here is code snippet
for (int i = 0; i<10; i++)
{
SetWindowText(filenames);
}
please help.! thanks.
SetWindowText replaces the current window text with the string you provide.
So, if you want to show multiple lines with it, you first have to create a multi-line string.
A quick example:
CStringArray names;
// Fill names
CString str;
for (INT_PTR i = 0; i < names.GetCount() ; ++i)
{
str += names[i] + _T("\r\n");
}
c_MyEdit.SetWindowText(str);
Another time-tested method of showing multiple names at once is the list box. MFC provides a nice wrapper with the CListBox Class (see http://msdn.microsoft.com/en-us/library/y04ez4c9%28v=vs.80%29.aspx). This has the added benefit of being scrollable and (optionally) sortable if the list is long.
I am making a page which pulls from the user's browser their preferred language, via the Request.UserLanguages....which returns a two letter code (ex. "en") or detailed code (ex. "en-GB") .
I basically get the string of user languages (they are in order of preference) and store them in a string array. Then I use a loop to check if the language code in the first position of the string array is any of the codes for a certain language (another string array hard coded in).
Is there a better way to do this? I'm noticing increased load time and am worried additional languages will further slow the page load...
if (!IsPostBack)
{ //Holds possible user languages preferences to check client machine against
String[] compJapaneseLang = { "ja-jp","ja","jp","jpn","euc","shift-jis" };
}
//Get client machines langugage preferences
String[] userLang = Request.UserLanguages;
//Loop through variation of preferences from possible user langugaes
for (int i = 0; i < compJapaneseLang.Length; i++)
{
//IF JAPANESE
if (userLang.GetValue(0).ToString().ToLowerInvariant().Equals(compJapaneseLang.GetValue(i).ToString().ToLowerInvariant()))
cc.JapeneseObject();
}
Thanks!
Storing them in a list turned out best, not really much else one can do....