Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Strange spaces in bound combobox


Strange spaces in bound combobox

Author
Message
Zvi
Zvi
Forum Guru
Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)

Group: Forum Members
Posts: 4, Visits: 22
The fields of first and last name are set to varchar(15) to eliminate the empty spaces but when running, the names in the combobox have a weird spacing issue. What's wrong?



I'm using VS 2015, VBnet windows form.



Attachments
zack
zack
Forum God
Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)

Group: Forum Members
Posts: 102, Visits: 110
Try using the .Trim method to removing any leading or trailing white space before posting to combobox.



FirstName = FirstName.Trim
Zvi
Zvi
Forum Guru
Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)

Group: Forum Members
Posts: 4, Visits: 22
UPDATE: I've managed to get the text aligned by using a fixed font (eg: courier) but now I still have the trailing spaces in the combo although the SQL is using VARCHAR which is supposed to hide the trailing spaces.



In the FORM_LOAD I tried without trim, which gives me the following result: (has extra spaces after first and last name)



http://www.vinewoodstudios.com/vbnet-font



Here's the query I use in FORM_LOAD to get this:



Me.VINEWOODSTUDIOS_DataSet.tbl_clients.Columns.Add("FullName", GetType(String), "client_id +' ' + client_first_name + client_last_name")

Me.Tbl_clientsTableAdapter.Fill(Me.VINEWOODSTUDIOS_DataSet.tbl_clients)

ComboBox_clients.DisplayMember = "FullName"



I'm not sure how to implement the TRIM function in the Query. I tried LTRIM and RTRIM but this doesn't help: (example of RTRIM: )



Me.VINEWOODSTUDIOS_DataSet.tbl_clients.Columns.Add("FullName", GetType(String), "client_id +' ' + RTRIM(client_first_name) + RTRIM(client_last_name)")

Me.Tbl_clientsTableAdapter.Fill(Me.VINEWOODSTUDIOS_DataSet.tbl_clients)

ComboBox_clients.DisplayMember = "FullName"







zack
zack
Forum God
Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)

Group: Forum Members
Posts: 102, Visits: 110
Try shrinking the size of varchar(15) to say varchar(10) and see if there is less white space between the names.



I realize this is not a solution, however it will at least give you further insight as to why it's doing what it's doing.
Zvi
Zvi
Forum Guru
Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)Forum Guru (150 reputation)

Group: Forum Members
Posts: 4, Visits: 22
I can confirm that this does shorten the spaces (I've already tried this in the past to confirm) so yes, I know it has to do with the amount of max characters I put in SQL server.
zack
zack
Forum God
Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)Forum God (1.3K reputation)

Group: Forum Members
Posts: 102, Visits: 110
I assume the data is entered into the database fields through textboxes. Perhaps you can try removing white space before writing to the database, or try setting the textbox maxlength property.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search