Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a Database i've stored various item entries ie. ItemName such as
abc 8"x12", xyz 4"
i've taken all the items in Radcombobox, but whenever i want the selectIndex it shows
\" added before existing " (ie. Inch in ItemName)in each selectedvalue of an ItemName, coz of that i cant get the selectindex of that item.
so my question is what is that being added to the ItemName(\") and how to remove that \" from the selectedValue to get its selectedIndex
here is my short code,

C#
RadComboBox comboBox = (RadComboBox)editItem[dtBoundColumn.ColumnName].Controls[0];
                string selectValue = comboBox.SelectedValue;
                //selectValue.Replace("\"", "");

comboBox.SelectedIndex = comboBox.FindItemByText(selectValue).Index;

I tried commented part but it didnt work.
thanks in advance.
Posted
Updated 15-Jul-12 21:19pm
v3
Comments
Kenneth Haugland 16-Jul-12 2:05am    
What error messages did you get while debuging?
durgeshtupkar10 16-Jul-12 4:13am    
while debugging,in string variable selectValue i'm getting value xyz 8\"x12\" for the selected item abc 8"x12", due to this it cant find SelectedIndex for the item xyz 8\"x12\" as it is there in table with text xyz 8"x12".
I understand the backword slash may be added due to double quotes in a string, but how can neglect the backslash to get the selectedIndex?
Sandeep Mewara 16-Jul-12 2:17am    
Did you see a \" in output/UI. In code it is ok if you see.
durgeshtupkar10 16-Jul-12 4:15am    
its while debugging,
due to that slash being added i cant get the selectedindex for that selected Item.
j.yanga 17-Jul-12 0:32am    
Is there a 'FindItemByValue()' method? Maybe you could use that instead.

1 solution

Hello there :)

First of all, please, remember to specify what type of an application it is (web/windows). Sometimes it comes very handy in both figuring out your problem and providing a solution.

Okay, in C#, there are few basics I've listed below:
1. Strings are always represented within double quotes
2. A single Backslash is used as the escape character in C#
3. In order to represent a string which contains double quotes or single quotes, you have to precede each of these characters with a single back slash
4. But when displayed on screen, .Net does NOT show these back slashes

If you understand these fundamentals, you'll understand that you cannot remove backslashes that are used as escape characters from a string.

Therefore, try these steps and see;
1. Create a test page/window with a radcombobox in it
2. Put some random hard coded values with double quotes characters in it
3. Pick a value and write logic to search the control with and with back slashes for that value

One of it should work, if it doesn't, post the code so we can see what you are doing.

Hope this helps, regards
 
Share this answer
 
Comments
durgeshtupkar10 16-Jul-12 7:25am    
Sorry, Its Web.
see,for this line of code,
comboBox.SelectedIndex = comboBox.FindItemByText(selectValue).Index;

whenever I select item of combo as
A-01-HEX NIPPLE 7/8"x 1" it shows String selectvalue as A-01-HEX NIPPLE 7/8\"x 1\" in debugging and gives me the correct comboBox.SelectedIndex, but when it comes for the item HEX NIPPLE 7/8" it shows selectvalue as HEX NIPPLE 7/8\" and throws an error as objectReferenceNotSetToAnInstance...

what cud be the issue?
CodeHawkz 17-Jul-12 0:02am    
oh it's a web :) Ok, the first thing I can see is that, you have not accounted for the exception that could occur if, the "FindItemByText(string value)" could not find your value. You should encapsulate it with a try/catch block.

Apart from that, since you are sure that the item HEX NIPPLE 7/8" is there in list of values, I think you might have white space at the beginning or end of your value. Try trimming all these values before you enter it to the list and in that line of code too.

comboBox.SelectedIndex = comboBox.FindItemByText(selectValue.Trim()).Index;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900