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.
Related
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.
I want to replace my values in text box without deleting them, for example, I output in my text box time "HH:mm:ss" and if I type in that textbox first number I would like to change "H" on it, and so on. How can i do that?
I don't ask code, just an advice.
I really need to get the contents of the line where the caret is blinking in a rich text box control. Suppose I have the following text in a rich text box:
This
is
a
test
I would like to retrieve the text of line 2 by providing its index (for example 2 or 1 if the function is zero-based).
Thanks in advance,
Vali
I'm not sure if the question's title and what you really want to know are the same... If you want to get a line given its index, check the Lines property of the RichTextBox.
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.lines.aspx
Make sure you have the WordWrap for the text box set to false to make sure the index of the line corresponds to the line where the caret is.
Try this:
var pos = richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart);
MessageBox.Show(richTextBox1.Lines[pos]);
you can do it
richTextBox1.Lines[1]
I've been having this problem for a few days. Whenever I update a label in a StatusStrip object it formats my text backwards. I send my label something like
toolStripVoltage.Text = batteryVoltage.ToString("F2") + " V";
and the label will display V 2.82.
and when I send it something like
toolStripVoltage.Text = batteryVoltage.ToString("0.00 V");
it will display the same thing. It seems like no matter how I format the string the "V" goes before the numbers. and! it still puts a space in between the unit and the number. And here's the kicker: when I call this same text to appear in a tooltip of another object like this
toolStripVoltage.ToolTipText = toolStripVoltage.Text;
It displays as 2.82 V. Any ideas on how I can make this work for me?
EDIT:
oh wow. I instantly figured this out somehow...the default RightToLeft property is Yes. I don't know why that would be! but the trick was to set that to No. Very strange for that to be the default setting.
I am using label in my winform . It displays the value which I enter in another textbox. My problem is label does not display whole characters I enter in textbox. Label's size is width=160 and height=19. So it truncates the last value. For testing purpose when I enter "W" in caps in textbox ;label can display maximum 13 "W"s. So I am trimming the
charater's by using labelname.substring(0,10); and for next three characters I am appending 3 dots(...)
But this solution is not desirable to my senior. He is telling me that if I enter all small letters "l" in textbox then though label has space to display more than 13 characters it will display only 13 characters(including dots).
Does anybody has solution on that ?? I also cannot increase width or height of label to accomodate more characters.
Well, you could set the AutoEllipsis property to true and don't worry about the length of the text.
Edited to Add: as per comments
If you're using RadLabel from Telerik then you need to dig a little more:
RadLabel.LabelElement.LabelText.AutoEllipsis
Nothing that 5 minutes looking through the documentation doens't solve
Set the AutoEllipsis property of your Label control to true. You can do this either in the designer, or through code:
myLabel.AutoEllipsis = true;
That will cause the ellipsis character (...) to be automatically appended to the text if it overflows the space available in the label. You won't have to manage this yourself in code at all.
This property is available as far back as .NET 3.0.
If I understand your question correctly, you can use Textbox.MaxLength property which only allows the user to enter the maximum number of characters you set the value to.
You can set the label's AutoEllipsis property to true and let it figure this out for itself.
Gets or sets a value indicating
whether the ellipsis character (...)
appears at the right edge of the
Label, denoting that the Label text
extends beyond the specified length of
the Label.