Thousand seperator does not work correctly in data gridview

270 Views Asked by At

please let me explain it clearly, if there is misconception please let me know,

firstly you suppose I have a grid with three column:

ItemName Count Fee

my code works perfectly when I click on ItemName and the go to fee column, mean in this case when I type 12345 it becomes 12,345 actually when I am typing.

but when I go to count column and then fee column it does not work for example when I am typing 12345 it does not put comma.

my code:

Public Override  string Text
{
    get
    {
        return base.Text;
    }

    set
    {
        base.Text=GetFormattedText(value);
    }
}


protected override void OnTextChanged(System.EventArgs e)
{
    base.OnTextChanged(e);
    Text= GetFormattedText(Text);
}

Protected virtual string GetFormattedText(string Text)
{
    string strText= text.Replace(",","");
    decimal  decValue=System.Convert.ToDecimal(strText);

    strText= decValue.Tostring("#,##0");
    Return strText;
}

More explanation I am sure something is wrong with the GET of my property, because in this case, I mean when I go firstly to count column and then fee column it just calls get and doesn't go to OnTextChanged,

I know my question seems stupid because of my little knowledge but I really appreciate it if you could share some ideas

0

There are 0 best solutions below