locked
TextBox in C# RRS feed

  • Question

  • When I bind a TextBox to a column in my database, if the column type is number (my database is Oracle 8i), I face a weird problem. As long as there is no information in that column everything is fine, but as soon as I put a number in that TextBox, there is no way you can clear it up. Apparently validation doesn't let you leave that TextBox blank any more. no matter what you do, you have to enter a number in it, before you exit.

    That's exactly the same if the column type is Date.


    Any idea ??!!!

    Thanks,
    Mathew
    Monday, June 2, 2008 8:19 PM

Answers

  • Mathew1972 said:

    When I bind a TextBox to a column in my database, if the column type is number (my database is Oracle 8i), I face a weird problem. As long as there is no information in that column everything is fine, but as soon as I put a number in that TextBox, there is no way you can clear it up. Apparently validation doesn't let you leave that TextBox blank any more. no matter what you do, you have to enter a number in it, before you exit.

    That's exactly the same if the column type is Date.


    Any idea ??!!!

    Thanks,
    Mathew


    Hi Matthew,

    I've answered similar problem here. This is only applicable if you're using DataSet. Maybe you can also apply it to some other frameworks.
    • Marked as answer by Mathew1972 Wednesday, July 23, 2008 8:50 PM
    Wednesday, July 16, 2008 9:47 PM

All replies

  • You can clear the textBox by putting this char in it: "\0"

    The DateTime is trickier, I suppose. You can try DateTime.MinDate; If this does not work, set the object to null and do a new instance. Or do Dispose ( ) and new instance.
    AlexB
    Monday, June 2, 2008 8:46 PM
  • Thanks,

    I tried it, but didn't work. I can just put a 0 and exit, but I need to change it to null not 0.
    When i change it to what ou said (\0), it still behaves the same and it doesn't let me exit.

    Mathew
    Monday, June 2, 2008 9:01 PM
  • It is strange. I remember people were able to clear MaskedTextBox this way.

    I'll keep thinking.

    Incidentally, it is not a char zero which is supposed to end up in the textbox but a control char \0. How do we do it?


    AlexB
    Monday, June 2, 2008 9:41 PM
  • Thanks Alex,

    Unfortunately, I didn't get what you exactly meant by the second part of your reply.
    What I did was basically putting exactlly \0 into the textbox to see if it lets me exit or not, which it didn't. Obviously in a real scenario, I have to make this kind of tricks programmatically behind the scene and I cannot expect user to enter such things to leave this field blank.
    This is one of the most ridiculous things I have ever seen. I have posted this question in MSDN forum a couple of times, but no result yet.
    Please let me know if you find anything.
    Thanks again,
    Mathew
    Tuesday, June 3, 2008 1:19 PM
  • Mathew1972 said:

    Thanks Alex,

    Unfortunately, I didn't get what you exactly meant by the second part of your reply.
    What I did was basically putting exactlly \0 into the textbox to see if it lets me exit or not, which it didn't. Obviously in a real scenario, I have to make this kind of tricks programmatically behind the scene and I cannot expect user to enter such things to leave this field blank.
    This is one of the most ridiculous things I have ever seen. I have posted this question in MSDN forum a couple of times, but no result yet.
    Please let me know if you find anything.
    Thanks again,
    Mathew



    I tried it with MaskedTextBox. didn't work either.

    Please heeeeeeeeeeeeeeeeeeeeeeeeeeeeelp !!!!!!!!!!!!!

    Tuesday, June 3, 2008 2:58 PM
  • Hi Mathew1972,

    Here is a sample in code project about how to mask a C# textbox control; perhaps you can get some inspiration.

    Masked C# TextBox Control

    If you still cannot figure the issue out, well, I want to recommend you post your code here.

    Regards,

    Xun

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, June 6, 2008 2:51 AM
  • Matthew, I reread your post. Sorry, been on a sick leave, still am. I think your problem has nothing to do with the textbox but with the dataSource. You must specify explicitly that those fields (columns) in the Oracle database accept nulls. I have never touched an Oracle DB and I have no idea if it is possible.
    AlexB
    Friday, June 6, 2008 1:14 PM
  •  For questions and discussions regarding client application development using Windows Forms controls and features, please see http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=8&SiteID=1

    http://www.peterRitchie.com/blog
    Friday, June 6, 2008 1:32 PM
  • Hello Xun,

    Thanks so very much for your reply. Your post is very useful for some other issues, but Unfortunately this masked property doesn't solve my problem. I tried what you said and created a new MaskedTBox class, but I have still the same problem.
    What I do and say is very simple and you can reproduce the following situation on your PC very easy, the only thing is that I have this problem with  an Oracle database and I have never tried it with SQl Server to see how it works. I don't even know what the root of this problem is. Is it in database side or application side?

    I bind a TextBox or MaskedTextBox to a Column in one of my Oracle tables. I have tested it with Number and Date type columns, and both have the same problem. The code is:

    TextBox1.DataBindings.Add(new Binding("Text", BindingSource1, "BILL_AVG", true));

    and in my datasource I set this field AllowDBNull property to be true.

    When I run the application and go this TextBox (TextBox1), as long as its value is null and I don't type anything in I can exit from it whithout problem. If I put a number in it and exit, it's still ok and behaves normally and lets me exit. Now, if I go back to this TextBox while it has a number value in it and I empty it, it doesn't let me exit anymore and it locks me in until I put a number value or zero. In another word, after it gets a value for the first time, it doesn't let you delete it whatsoever and you can just change it to another value of the same type to exit.

    This isn't only my problem. We are two developers in our company and we both have the same problem. I have posted this question in many forums, but I haven't got any solution for it for almost 2 years. If I'm not clear, don't hesitate to ask your questions. There are no more codes involved.

    Thanks in advance for any kind of help or clue.
    Mathew

    Thursday, July 3, 2008 7:49 PM
  •  Now, if I go back to this TextBox while it has a number value in it and I empty it, it doesn't let me exit anymore and it locks me in until I put a number value or zero

    Well, it is absolutely clear from you description that it has nothing to do with the TextBox but with the Binding Source. Your Oracle DB does not allow nulls apparently. I don't understand why it takes null values first time around but it may be something specifically of an Oracle issue.

    You have to set up AllowNulls property to true, that's it.

    In actuality there is a complication here. I don't think the default value for textBox.Text property is null. There is no such thing as a null string. There is an empty string but it is not null. Anyhow, it is between you and Oracle. It has nothing to do with either C# or TextBox fo this matter.

    Sorry.
    AlexB
    Thursday, July 3, 2008 8:30 PM
  • Thanks for your reply Alex,

    The Oracle connection object that I use is OracleDataAdapter, and as I said I checked the AllowDBNull property of my datasource to true. Also, in my table this column is a null column, so I'm positive that there is nothing wrong in the database side. I don't know if there is any bug in the OracleDataAdapter that causes this, but other than that the only culprit can be TextBox.

    As you implied in your last paragraph, I don't know how TextBox is blank when we insert a new row and I can save this new record the way it is (it shows I have no problem with the null value in that column, neither in my table nor in my datasource nor anywhere else), and I consider it as null value for that Number column, but the weird is why it doesn't let you make it blank as soon as you put a number in it.

    I'm sure this is a Microsoft Bug. There might be a trick to handle this, but this is a bug in TextBox, no doubt about it.
    Please ask anybody you know who work with Oracle to see if they have any work around on this.

    Thanks,
    Mathew
    Monday, July 7, 2008 9:44 PM
  • There could be an Oracle forum around, even here on MSDN. It seems you are stuck. Sorry. I definitely have neither new ideas nor any prior experience with Oracle. 

    Also keep it in mind that too many people work with a combo TextBox + Sql Server, TextBox + Excel, textBox + other binding sources, OleDb, etc and nobody has ever reported anything like that. Think about it. The fact that you haven't gotten any feedback at all in this forum where Oracle experience is very scarce but people work with other DBs extensively tells you what the truth is. I remain convinced that the TextBox has nothing to do with it.

    Another piece of logic. The TextBox is a groundswell, basic control that has been around for years, survived .NET 1.0, 1.2, 2.0, 3.0, 3.5 etc, etc, etc. How come nobody noticed such an elementary bug?

    I wish you best of luck in your pursuit of the bug issue.
    AlexB
    Monday, July 7, 2008 10:10 PM
  • Monday, July 7, 2008 10:13 PM
  • Mathew1972 said:

    When I bind a TextBox to a column in my database, if the column type is number (my database is Oracle 8i), I face a weird problem. As long as there is no information in that column everything is fine, but as soon as I put a number in that TextBox, there is no way you can clear it up. Apparently validation doesn't let you leave that TextBox blank any more. no matter what you do, you have to enter a number in it, before you exit.

    That's exactly the same if the column type is Date.


    Any idea ??!!!

    Thanks,
    Mathew


    Hi Matthew,

    I've answered similar problem here. This is only applicable if you're using DataSet. Maybe you can also apply it to some other frameworks.
    • Marked as answer by Mathew1972 Wednesday, July 23, 2008 8:50 PM
    Wednesday, July 16, 2008 9:47 PM
  • Gio Bejarasco said:

    Mathew1972 said:

    When I bind a TextBox to a column in my database, if the column type is number (my database is Oracle 8i), I face a weird problem. As long as there is no information in that column everything is fine, but as soon as I put a number in that TextBox, there is no way you can clear it up. Apparently validation doesn't let you leave that TextBox blank any more. no matter what you do, you have to enter a number in it, before you exit.

    That's exactly the same if the column type is Date.


    Any idea ??!!!

    Thanks,
    Mathew


    Hi Matthew,

    I've answered similar problem here. This is only applicable if you're using DataSet. Maybe you can also apply it to some other frameworks.



    Thanks very much Gio.
    Cheers,
    Mathew
    Wednesday, July 23, 2008 8:51 PM
  • Hi Mathew,

    I'm probably very late with my reply but i encountered something similar today.
    what u can do to prevent it from locking up is setting the formatting to false at the end of the databinding command.

    this

     

    .priceTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.tblProduktenBindingSource, "Price", false));

     

    // Parameters:
    // propertyName:
    // The name of the control property to bind.
    // dataSource:
    // An System.Object that represents the data source.
    // dataMember:
    // The property or list to bind to.
    // formattingEnabled:
    // true to format the displayed data; otherwise, false.


    Monday, June 8, 2009 9:38 PM