Ok weird thing I am pulling my hair out with
I have a text box which is being filled by a value from the database (a telephone number)
I have breakpointed the app and checked the value going in to the textbox and the value in the textbox after the assignment and have found it to be correct (07865 345 632)
However when the textbox is shown there appears to be several leading spaces which dont show in the breakpoint info.
Moreover when I then try to assign that value from the text box to a variable it shows and is saved as the original without spaces.
Is there anything that would make this happen without me knowing? does the breakpoint info remove leading spaces in some circumstances?
3 hours on this issue and no progress so any help would be great.
Summary
value recieved from database BEFORE assignment to textbox: "07865 345 632"
value shown in textbox: " 07865 345 632"
value assigned to variable from textbox: "07865 345 632"
Visual Studio 2010 - C# - Windows Forms - SQL Server 2008
HELP! (I only have six hairs and three of them are loose! :-))
Related
In my project I need a control that allows me to enter 2 columns.
First column is an Id Number
Second column is some Text.
Example...
row 1 Id = 1 Text = Day Shift
row 2 Id = 2 Text = Night Shift
But I only want to display the Text Values and then have the user select either Day Shift or Night Shift.
The program can then just lookup the corresponding value (1 or 2) for whatever text they chose.
- In Microsoft Access I would just have used a ComboBox and hidden the first column.
I cannot find anything in Visual Studio 2017 to put on my Windows Form that easily does this.
I want to set it all up at design time and the closest I have come so far is by using a LISTVIEW control using a display type of LIST (I don't want column headers either.
It seems to do what I want except that it always wants me to leave a blank space below my lines of text - presumably for a horizontal scrollbar even though I set it to False in the properties and it does not actually display a scroll bar.
If I resize the ListView control to just be big enough for my two rows of text it tries to display the 2nd row next to the 1st row and still leaves a blank space below the rows.
See the below images, assuming I uploaded them properly, I am totally new to asking questions here.
Is there a way I can achieve this - should I be using a different control?
The closest I came to what I need is the top image
[![enter image description here][1]][1]
Thanks and I hope it all makes sense.
In reply to Harry I added the below...
After adding the ListView control to my form I then clicked on the little arrow selector (in the top right of the ListView control).to bring up the collections list popup box.
It is there I set the view to be ‘List’ so I don’t have to have column header, then I clicked on EDIT ITEMS to get another pop-up screen…Click the [Add] button to add items in the rows.
Then I changed the Text to ‘Day Shift’ for the first member (and ‘Night Shift’ for the second member).
To add values in the rows for the 2nd column I then clicked the SUBITEMS (collection) box in properties to get the next popup…
I then clicked the Add button and created a new Text item (value 1)
and repeated this for the Night Shift member but gave it a value of 2.
These values are to be the actual ID values (in the 2nd column).
Note…
I did create column Headers but setting the View to List means I don’t get them displayed (and don’t want them displayed).
but I did notice that changing the View to List also removes the second column (Id) from the ListView display.
As I don’t need the Id values (1 & 2) displayed I am not going to worry about what happened to them disappearing in the display. All I did, though, was just changed the View from Details to List.
Sorry If I’m misunderstanding you but at this point there is no actual code I am creating, no doubt Visual Studio 2017 does that itself but I am not looking at that. Is that what you needed to see?
Hope this makes better sense though, I did try and include images but the system will not let me do that until my reputation points are higher, sorry.
Thanks
This is the first time I've experienced something like this. As far as I know I've done everything as they should be and for the most part it did output what I wanted but somehow there were unique bugs that seemed impossible.
It all started with a combo box that I populated with this code:
items.Add(new { Text = dr4["item_name"], Value = dr4["item_id"] });
It did the trick and filled the combo box with the 131 rows of item names in the combo box. But while scrolling inside the combo box, I found two items that were occupying two lines. I don't know how this happened, all of the items that were inserted in that combo box underwent the exact same way since I looped the code above so the problem could have not been from there. I double checked my database to see if I had some extra spaces or characters but they didn't and was normal as the rest of the 129 rows.
I tried creating a textbox and tried to fill it with both the combo box's text and value using this code:
textBox.Text = comboBox.SelectedValue.ToString() + comboBox.Text.ToString();
I had some interesting results. The 129 rows of data appeared right next to each other (not even a space) BUT the 2 specific rows of data appeared as if someone pressed enter after the selected value was printed.
For the sake of further explanation, let's say the selected value was "5" and the text was "This is number 5":
Now, the textbox's text output from the 129 rows were:
5This is number 5
While the textbox's text output from the 2 other rows where:
5
This is number 5
Now I don't know how this is happening and can't even explain it myself as they're both all from the same table, it couldn't be their length because there are longer texts from the other text from the 129 rows than the 2 other rows that's behaving unexpectedly.
I can't understand where are they getting this extra characters from, there doesn't seem to be any pattern. I think this has something to do with the devexpress combo box I'm using. I've tried populating a normal visual studio's combo box and it produced my desired output, all of the 131 items inside the combo box were normal.
Good Day!. I am trying for retrieving Local database values and showing into textBox.!
I have to put a very long text on a " textbox " , and I need a local database to read the text to be put into the text box .
How do I enter text inside the database ? how do we associate the text to textbox ?
I'm looking for a simple example , which only this , a textbox and a database.Ho found tutorials but are dispersive
you must first look at the 31 days of Mango, specially the day #30
I have 2 combo boxes on a winform, both dragged onto the surface via the designer, both get their items from a database both connect to the dbase fine and are populated properly. But one of them, when it has focus, the selected item is not visible; all that can be seen is the blue background highlight. I have compared the properties of both and cannot discern any setting that is different and that might cause this. When the combobox loses focus the selected item is show, black foreground on a white background as would be expected.
Have a look at the data that is in the Display Member. This might end with blanks/white spaces.
I had this same issue when the combobox was populated using a dataset from an SQL Database.
After changeing the select statement to remove leading and trailing spaces it worked as expected.
The explanation for me:
When editing/having focus, the combobox shows the text right-alligned in reverse video. If the text ends with a lot of blanks, as happens if you have SQL database with fixed length fields that are padded with spaces at the end, the result is that it shows the spaces at the end of the value (right alligned). If you remove the spaces in the select-query (in MSSQL this is done by ltrim(rtrim()) as the text of the selected item is not padded with spaces on the end, therefore it shows the text (in reverse video) until the focus is lost.
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.