winforms

Posted by Madhavi under C# on 2/11/2010 | Views : 2450 | Status : [Member] | Replies : 17
Hi

I am new to winforms but worked in web applicaion. I have an issue at enduser, but unable to replicate at my end.

There is one text box and three search buttons. ( Searchy by visitorname, by ID, by company). when user enters characters in texbox, datagrid view shows the records matching the entered string. internally there is method which will cross check whether entered character is within ASCII code 0-256

Issue is :

when clikced on search by company name , a pop up window comes, saying inputstring was not in correct format.


       System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32 (String value)
at grt.utility.CharactorToLetter.GetOneIndex (String OneIndexTxt)
at grt.utility.CharactorToLetter.IndexCode (String IndexTxt)
at grt.FrmVTRExpToday.tbSearchContent_TextChanged (Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



code snippet roughly:

tbSearchContent_TextChanged(Object sender, EventArgs e)   
{


string letters = this.charactertoletter.IndexCode(enteredstring); // charactertoletter is another cs page where the IndexCode methos lies
}

...................
public String IndexCode(String IndexTxt) 
{
String _Temp = null;
for (int i = 0; i < IndexTxt.Length; i++)
_Temp = _Temp + GetOneIndex(IndexTxt.Substring(i, 1));
return _Temp;
}

private String GetOneIndex(String OneIndexTxt)
{
if (Convert.ToChar(OneIndexTxt) >= 0 && Convert.ToChar(OneIndexTxt) < 256)
return OneIndexTxt;
}


First two search buttons are working fine. Can any one help me on this issue.




Responses

Posted by: Vuyiswamb on: 2/11/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
please show us the code on the Click event of button that does the search by company name.

NB: Always use code tags if you want to show the code.


Thank you for posting at Dotnetfunda
[Administrator]

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/11/2010 [Member] Starter

Up
0
Down
Hi Vuyiswamb

Thank u for your quick response. I am in pressure to solve this .


Code in click event button :

private void btnSrhbyCompany_Click()

{
if (_pressedButtonIndex != 2)
{
refreshReleasedButtonImage(ImageButtonGroup[_pressedButtonIndex]);
refreshPressedButtonImage(ImageButtonGroup[2]);

this._pressedButtonIndex = 2;
this._searchTag = Enums.SearchTag.SeachByCompanyName;
this.tbSearchContent.Text = "";
this.ActiveControl = tbSearchContent;
}
}



Madhavi


Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/11/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Place the a Break point in the Beginning of the Button and press F11 to navigate and tell which line it gives a problem

Thank you for posting at Dotnetfunda
[Administrator]

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 2/11/2010 [Member] Bronze

Up
0
Down
send ur form snap write what is ur problem

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/11/2010 [Member] Starter

Up
0
Down
Hi Vuyiswamb,

Unable to replicate it.That is the main problem. Issue is existing at enduser where application's exe is installed. I got the Details from there - (Error detaisl in my first post) . As error is saying input string was not in correct format , it appears to me like problem lies here where corresponding ascii code is given for entered string.

at System.Convert.ToInt32 (String value)  .


Kindly correct me if my assumption is wrong.
When tested at my end through debugging placing breakpoints, searchbycompany is working fine. Unable to replicate even.

Sagar - Kindly go through my first post for details of my problem. Unable to provide snap as it is confidential .

Madhavi


Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/11/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
I suggest you replace the Clients Program with the one that you have now , if you say its working. its Difficult to correct something you dont know. it might be an Environment issue. But i Suggest you add a try and catch in your code to catch the Error and tell you exactly what is the Problem.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 2/11/2010 [Member] Bronze

Up
0
Down
Hello Madhavi,

It must be an environment issue then as you are not getting error at your end but end user has an issue. Better try to place your code in try catch block and keep messagebox where ever needed in order to track the values at end line.

++
Thanks & Regards,
Deepika

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/11/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Also you can register your application to UnhandledException.

This will also give you a chance to write log when something unusual happens.
See this :
http://www.codeproject.com/KB/exception/UnhandledExceptionClass.aspx

www.abhisheksur.com

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 2/11/2010 [Member] Bronze

Up
0
Down
Can you please check the code passes in the Convert.ToInt32

This may cause from following reasons.
1. Text may be null
2. Text not in valid Integer format

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/15/2010 [Member] Starter

Up
0
Down
Hi

Error (stack)Trace is showing that at below line it is failing( Please refer to my first post).

System.Convert.ToInt32 (String value



But in code i am using to check whether falls in 0-256 range or not

if (Convert.ToChar(OneIndexTxt) >= 0 && Convert.ToChar(OneIndexTxt) < 256)



My doubts are :
1. I didnot use Convert.ToInt32() . Where it lies in my code?( am using Convert.ToChar (String value))
2. Can i replace Convert.ToChar (String value) to Convert.ToInt32(string value)
3. Is the behaviour of both same.

Madhavi








Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/16/2010 [Member] Starter

Up
0
Down
Hi,

THanks one and all who responded for my post.

Got the catch where the isssue is. while generating the unicode for the entered string , character by character, went out of range of 0-256. That character is En Dash whose unicode is 8211. Really it is out of my mind, how the user who have minimum knowledge typed this character. Till now I don't Know.This En Dash is typed by Ctrl+Alt+Hyphen from NumPad which looks like minus but not. There are some characters like this called Em Dash (8212) which fall out of range of 0-256 .


As solution to this i thought like restritct the user entering out of range of 0-256 in textbox which can be achieved by two ways.
1.Using "Regular expression " in textbox_textchange event
2. Using Textbox_keyPress event which uses e.KeyChar

Kindly any one suggest which one is better to follow , or is there any other way of achieving this. please send example if possible


Thanks
Madhavi




Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/16/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Great to see that you solved this yourself.

Cheers.
Happy Coding.

www.abhisheksur.com

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 2/17/2010 [Member] Bronze

Up
0
Down
Good to see you got a solution to it.

But i would say you can trap it in keypress event itself.

++
Thanks & Regards,
Deepika

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/17/2010 [Member] Starter

Up
0
Down
Hi

Thank u for suggesting to use Key press event. But,today my client want such that textbox should accept all the characters whatever user types including Em dash, En dash whatever( i don't know what other special characters out of 0-256 range). I thought I gave max range covering all characters, but to my suprise user entered En Dash character.

Does any one know the list of this type of special ( so special ) characters .

Madhavi

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 2/17/2010 [Member] Bronze

Up
0
Down
You can check out a list of special characters here:

http://www.yourhtmlsource.com/text/specialcharacters.html

Hope it helps

++
Thanks & Regards,
Deepika

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhavi on: 2/18/2010 [Member] Starter

Up
0
Down
Hi

Thank u so much for sending the link. Changed my code accordingly



madhavi

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 2/18/2010 [Member] Bronze

Up
0
Down
Good to hear that you got it solved!!

++
Thanks & Regards,
Deepika

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response