Question Combobox selected Item issue

Socarsky

Well-known member
Joined
Dec 27, 2012
Messages
173
Location
Jakarta/Indonesia
Programming Experience
Beginner
I faced with that issue which appears with spaces after letters finished more than Combobox.SelectedItem's length.
Why? How can I fix this issue?

Below is showing my issue as visual its a very short and small video.


Combobox SelectedItem Issue - YouTube
 
Probably They come from MS Sql data type property, but I am not sure that. Only related not matching appearing.
 
I know Trim() function and I also used it with a few way to get a text with with space while passing ComboBox.SelectemItem but failure. This is not passing a chosed selecteditem.text to a variable.
 
Here is the issue's solving :) It was easy to catch the idea after I focused well to a property of textbox which is autocomplete.:applouse: Its just need not to be give up

solvingerror.png
 
Hi Socarsky,

I though I would add a post here since, I for one, have been totally confused with this thread. In post No.1 you demonstrated a Multi-Column CUSTOM ComboBox which no one other than YOURSELF have access to so I did not post anything since trying to answer your question would have been a total stab in the dark since none of us here knows how your Data is applied to your ComboBox. You may want to consider that for the future.

It now seems that you have solved your problem but what post No.9 has to do with post No.1 is just confusing. That aside, here are a couple of points of interest in that tbStock code block you have posted:-

1) You should not really use a Try/Catch block like that where you have encased everything in the routine within a Try/Catch block. You should only place the code that you consider may cause you problems at some point in this block. Lets say then that this should be the Database access code only. In addition to this if an error did occur during the Database access would your Database Connection close? The answer is No since your close statement is the last call in the Try block. The best way to do this would be to use a Try/Catch/Finally block where the Finally block is ALWAYS fired regardless of whether an exception occurred or not. You would then test to see if the Database connection is open here and then close it if necessary.

2) Why have you declared a DataSet when all you do is add a DataTable to it and then do nothing else with it? In this case you read data into a DataTable and then add the information you need to a TextBox's AutoCompleteCustomSource so get rid of the two references to the DataSet

3) Your SQL Select query is NOT wrong but is technically incorrect. To have a WHERE clause on a Text Field searching for the value of LIKE '%' is exactly the same as having NO WHERE clause so get rid of it. This should be:-

VB.NET:
Select RTrim(sCode) From tbStock

4) You declare "r" as a DataRow but you can get rid of this and use a slightly more elegant form in your For Loop such like:-

VB.NET:
For Each myRow As DataRow In dt.Rows

Hope that helps.

Cheers,

Ian
 
I though I would add a post here since, I for one, have been totally confused with this thread. In post No.1 you demonstrated a Multi-Column CUSTOM ComboBox which no one other than YOURSELF have access to so I did not post anything since trying to answer your question would have been a total stab in the dark since none of us here knows how your Data is applied to your ComboBox. You may want to consider that for the future.
I thought that video was enough to specify my issue and that's why I've not given enough details in that project.
1) You should not really use a Try/Catch block like that where you have encased everything in the routine within a Try/Catch block. You should only place the code that you consider may cause you problems at some point in this block. Lets say then that this should be the Database access code only. In addition to this if an error did occur during the Database access would your Database Connection close? The answer is No since your close statement is the last call in the Try block. The best way to do this would be to use a Try/Catch/Finally block where the Finally block is ALWAYS fired regardless of whether an exception occurred or not. You would then test to see if the Database connection is open here and then close it if necessary.
You are right that I should have given a place to type Try/Catch block. But Believe me It was on my mind to do after other obstacles to handle. I will make it Ian, Thanks
2) Why have you declared a DataSet when all you do is add a DataTable to it and then do nothing else with it? In this case you read data into a DataTable and then add the information you need to a TextBox's AutoCompleteCustomSource so get rid of the two references to the DataSet
Yes Its my fault memory consumption but Its nothing in a my code.
3) Your SQL Select query is NOT wrong but is technically incorrect. To have a WHERE clause on a Text Field searching for the value of LIKE '%' is exactly the same as having NO WHERE clause so get rid of it. This should be:
I dont know about that and usage too, sorry. That one which I used that it looks enough to make it after my issue has taken a few days to handle.
You declare "r" as a DataRow but you can get rid of this and use a slightly more elegant form in your For Loop such like:-
I think your suggestion does not bring a big difference in my usage way.

Thanks a lot for your advice and the way of points are corrrect.
Cheers,
Sinan
 
There is something important which I just learned it a couple days ago so this topic accually related with it that what I express now. Char data type causes this issue in MS SQL I only care now MS SQL that I cannot tell about this matter for the others. If you use char datatype that must be completely the same length that you decide, I mean if you assign 10 characters then it must not be fewer than you assign if you do that then you will face with whitespace when every you pass or bind data. I changed some columns data type as varchar or nvarchar then whitespace disappear. Char data type suits for credit card number, phone number or exactly same length.
 
Back
Top