I'm creating a Desktop App in Visual Studio With C#.
I've a String array called Tag_Word_Box. In a textbox if I type something, then it will be show suggest words from Tag_Word_Box array.
In briefly, assume that- I've 5 words respectively [aabc] [abc] [abd] [abcg] [bcd] If I type in textbox only 'a' then it will be show all of words without 'bcd'.
If I select 'aabc' or press enter one of suggesting words, then- it will be assign whole word in textbox, that means textbox value will be changed with selecting word by 'a'.
BTW, I know that- it will be solved by trie algorithm to find out words. But I want to know that how to do that operation in visual studio respect of C# that-
1. to show suggesting words when I type something
2. and how do I change textbox value by selecting from those?
Thanks :)
All textboxs have an 'AutoCompleteSource' property. Set it to CustomSource from the Properties toolbar. Then set the 'AutoCompleteMode' property to SuggestAppend. Now, in the code, add this to the TextChanged Event of the textbox:
var autocomplete = new AutoCompleteStringCollection();
autocomplete.AddRange(Tag_Word_Box);
textBoxName.AutoCompleteCustomSource = autocomplete;
To do the complete thing in code, add this to the TextChanged event of your textbox:
textBoxName.AutoCompleteSource=AutoCompleteSource.CustomSource;
textBoxName.AutoCompleteMode=AutoCompleteMode.SuggestAppend;
var autocomplete = new AutoCompleteStringCollection();
autocomplete.AddRange(Tag_Word_Box);
textBoxName.AutoCompleteCustomSource = autocomplete;
Remember to replace textBoxName by the name of your textbox before using this code.
Related
/*I am reading many files and getting data through File.ReadAllLines. Now I want to search in these files for a specific string written in a textbox. Whenever I put some text in the textbox it must return lines of text containing that word. I am coding in textchanged property but it is not successful as it gives me a result even when I press backspace or add any other word. */
I have successfully made it to work. I was clearing the listbox every time it runs else statement. Now I just want you people to tel me what should I do to make it work fast.
if you don't want to get the result right away when you type something in Textbox then put Button on your form and try this code:
string[] lines=File.ReadAllLines(path);
var result = lines.Where(l => l.Contains("text")).ToList();
I hope this helps
I have written a GUI application that contains a DataGridView in which users can add new instances of an Arrow class by creating a new line in the view and filling in the new Arrow's properties. One of those properties is called transferType and is a string.
I allow users to set a list of valid transferTypes in a settings form. I am using Properties.Settings to save the settings, using the convent tool built into Visual Studio to create and manage application settings.
Rather than having the user enter the transferType field by hand and have the DataGridView reject the entry if it does not match any of the valid transferTypess, I have been trying to set up the column of the DataGridView to use drop down menus populated with the valid options. To do this, using Visual Studios GUI Design tool(which was used to build the GUI) I edited the column and changed the "Column Type" from DataGridViewTextBoxColumn to DataGridViewComboBoxColumn. That change allows me to select a DataSource to populate the selections of the combo box, so I went and under "Other data sources" attempt to select "Properties" which stores my settings (Properties.Settings.Default), but for some reason Visual Studio won't allow me to select it.
I then tried set the DataSource of the combo box in code after the initialization of the GUI, using the line" ((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes; (Transfer Type is the fourth column), but when I ran my program I get this error when I click on the combo box and try to "drop it down":
The following exception occured in the DataGridVIew:
System.ArgumentException: DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle to DataError event.
The error loops and reappears immediately after hitting OK or exiting the window.
I'm assuming that there has to be a reasonable way to use my settings to populate a combo box, but can't figure out how. I also don't understand why Visual Studio won't allow me to create a DataSource using Properties. Any help would be appreciated.
(This is also my first posted question, so be gentle with the criticism please :) )
UPDATE:
It turns out that using ((DataGridViewComboBoxColumn)arrowView.Columns[3]).DataSource = Properties.Settings.Default.validTransferTypes; does correctly populate the combo box, but any time the combo box is moused over, the previously mentioned error comes up.
If you are using Properties.Settings.validTransferTypes as a string then the value of that combobox would only be a single string value. Do you have more values in your settings that you'd like to populate the combobox with? It seems that the error is coming because you have nothing else for the combobox to read other that the single string you are loading in. Trying to load an array with Properties.Settings.Default may be an option and then setting the datasource equal to that array.
How do you get the values of their textboxes and transfer them to richtextbox?
I created a windows application form that contains a button1, a richtextbox, and a webbrowser(set to facebook.)
I want this button1, that if clicked, it will then copy the values that were typed in the registration forms of facebook.com and then pastes it to the richtextbox.
These are the IDs of their text boxes.
"firstname"
"lastname"
"reg_email__"
"reg_email_confirmation__"
"reg_passwd__"
"sex"
"birthday_month"
"birthday_day"
"birthday_year"
How do you programmatically get the values that were typed in the facebook textboxes and then transfer them to richtextbox?
Are you asking for someone to write the program for you? Doubt that will happen.
So, ignoring the obviously question of "why?", I'll give a few pointers.
First, look at the View Source of the page you are intereted in. It can sometimes be easier (with fixed formats - especially with textboxes that have fixed and unique names) to scan through the html source as text and just substring out the tags with the names you want. If the textboxes are not populated at build time (i.e. the values are not in the view source), then you will probabably have to go through the DOM and access the controls individually.
Depending how and when you are accessing this page, you may well find these fields are not populated at all by FB (for the obvious security reasons) and only act as input from the user (hence my "why?" question earlier).
Assuming that you are working with WinForms you can do use the WebBrowser control's Document property. It returns an object of type HtmlDocument. HtmlDocument in turn has a method GetElementById returning an object of type HtmlElement. The OuterHtml property finally contains the information about the textbox. Using a Regex expression you can extract the required info
HtmlElement tb = webBrowser1.Document.GetElementById("firstname");
string outerHtml = tb.OuterHtml;
// Yields a text which looks like this
// <INPUT id=firstname class=inputtext value=SomeValue type=text name=firstname>
string text = Regex.Match(outerHtml, #"value=(.*) type=text").Groups[1].Value;
// text => "SomeValue"
I would prefer to be able to access the HTML-DOM object model; however it seems to be hidden from c#.
EDIT:
The ComboBoxes yield a different kind of information. Note that I use the InnerHtml here.
HtmlElement cb = webBrowser1.Document.GetElementById("sex");
string innerHtml = cb.InnerHtml;
// Yields a text which looks like this where the selected option is marked with "selected"
// <OPTION value=0>Select Sex:</OPTION><OPTION value=1>Female</OPTION><OPTION selected value=2>Male</OPTION>
Match match = Regex.Match(innerHtml, #"<OPTION selected value=(\d+)>(.*?)</OPTION>");
string optionValue = match.Groups[1].Value;
string optionText = match.Groups[2].Value;
I have the following code:
txtbox1.Text = listView1.SelectedItems[0].SubItems[11].Text;
The value of the selected item of the listview is "33,5" but when the code reachs this line, in the textbox writes 34,00.
I don't know why if there's a text inside a text, I have tried convertingo to decimal before asing to the textbox but still put 34,00. I've tried too puting 33.5 instead of 33,5 but then the code writes in the textbox: 3350,0.
What can I do?
Thanks
try this:
string number = listView1.SelectedItems[0].SubItems[11].Text;
and check in debug mode what number contains.
I am convinced you have the right value in there, a simple string, but the txtbox1 is applying certain formatting on text change. You should find this out and fix the way content of txtbox1 is formatted after assignment.
// [in designer] textBoxInContext.AutoCompleteMode = Suggest
// [in designer] textBoxInContext.AutoCompleteSource = CustomSource
AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
autoComplete.AddRange(myArrayofStrings);
textBoxInContext.AutoCompleteCustomSource = autoComplete;
I have this code which works well as documented in MSDN. Problem: if user types "PS" it shows all the string starting with "PS"; I would like to display all the strings containing "PS"
Any pointers ?
If you don't find another way, I suggest doing it manually:
Use a combobox with no items(you'll fill them manually later).
Have a string array with your possible suggestions.
At the combobox.TextChanged or KeyUp event take its text and compare it to your string array whichever way you want and, after clearing the combobox.Items, add the found results to the combobox.Items and make sure to set the DroppedDown property to true if you have found suggestions.
The stupid but fun suggestion: make a class that inherits from AutoCompleteStringCollection and play with it in debug to see if you can fake this out.
The normal suggestion: make your own autocomplete with a listbox.