DataType

hi all,
when writing a single data (f.e. 'F' or '2') in a textbox, is it possible to get the type of this data
when i try to get the type by myTextbox.GetType() everything is a string...

is there any way, to get the type of the data, that is written in a textbox

thanks in advance,
.k


Answer this question

DataType

  • Vladimir Savinov

    I am not sure what kind of "type" do you expect in the textbox. If you enter just one character, you can use the first char of the Text property and use Char methods to test if it's a digit, letter etc.
    But remember, these methods test in Unicode context, for example there are more letters than the ones in the latin alphabet (A-Z) and if you need only these use (Char.IsLetter(c) && c <= 0x007a) test.


  • Marfig

    ok, thanks.
    but i guesss there is no way to just get the type ...
    with convert.to* i can convert to whatever i want to, but i only need to know what type the data is...

  • markp5511

    you can use the static methods in the Convert class to check type.

    Convert.To*() where * is a type

    Convert.ChangeType()


  • sonali1754

    Probably what you are trying to do is just to prevent some characters from being entered into the textbox, if so, you can write an event handling procedure to handle the TextBox control's KeyDown event:

    <TextBox KeyDown="OnKeyDownHandler" />

    Then in the code beside file, you define the event handler as follows:

    void OnKeyDownHandler(Object sender, KeyEventArgs e)
    {
    if ((e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
    && (e.Key < Key.D0 || e.Key > Key.D9)
    && (e.Key != Key.Back))
    {
    // Prevent non-numeric characters from being entered by user.
    e.Handled = true;
    }
    }

    Sheva


  • DataType