DataGridView problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mynkow
    New Member
    • Jul 2007
    • 37

    DataGridView problem

    Hi,

    I have a dataGridView with textBoxColumn. I have an Enum type with 3 values. The property ValueType is set to the enum

    dataGridViewTex tBoxColumn1.Val ueType = typeof( EnumType );

    But when I enter a value that is not in the Enum I get an Error Window that tells me that I am not handled exception in System.Enum.Par se(...). How can I handle this exception ( where??? ).

    The Exception
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You would have to put a try/catch block around the insertion.

    But you should read what you are saying.
    You want the column to be of the enum values...but you are trying to insert a non-enum value.
    That would be like having an int column and wondering why "jane doe" is not allowed to be inserted into it.

    Comment

    • mynkow
      New Member
      • Jul 2007
      • 37

      #3
      That is the point. I want to catch values that are not in the Enum.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Does this work?
        Code:
        try
        {
        EnumType mytest = (EnumType)SomeValue;
        }
        catch(Exception ee)
        {
        //didn't work
        }

        Comment

        • mynkow
          New Member
          • Jul 2007
          • 37

          #5
          No.

          If this can help...

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Have you tried any the events for the DataGridView object?

            Possibly usefull events:
            myDataGridView. CellParsing
            myDataGridView. CellErrorTextCh anged
            myDataGridView. CellErrorTextNe eded

            Comment

            • mynkow
              New Member
              • Jul 2007
              • 37

              #7
              When occurred this kind of exception the DataGridView calls "DataError" event where I can handle the Exception.

              Code:
              private void dataGridView1_DataError( object sender, DataGridViewDataErrorEventArgs e )
              		{
              			System.Diagnostics.Debug.WriteLine( e.Exception.Message );
              		}

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Hehe, you know I went looking for a DataError event and somehow managed to miss that exact one.
                Good find.

                Comment

                Working...