Type validation nightmare in windows form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TonFrere
    New Member
    • Nov 2007
    • 14

    Type validation nightmare in windows form.

    Hello,
    I have a visual C# application that is binded to a Sql server DB. I'm experiencing a lot of frustration when it comes to bind a combobox to a specific table. It seems that validation never succeeds.

    Two tables are involved:

    RMA
    --------------------
    RMA_Num - integer
    FAB_Num - integer
    ...

    FAB
    --------------------
    FAB_Num - integer
    Desc - string

    Of course you have guessed that the combobox is for the FAB field.
    Here is how my combobox is set:
    DataSource: FABBindingSourc e
    DisplayMember: Desc
    ValueMember: FAB_Num
    SelectedValue: RMABindingSourc e - RMA_NUM

    The list is perfectly displayed but when I select a value and try to save, the combobox field doesn't go through validation.

    I'm more of a database guy so to see what was wrong, I change the type of RMA.FAB_Num from INT to Varchar(50) in the database; recreated my datatables and tried it again. Guess what? It worked: the FAB_Num (an integer) saved as a string in my database main table.

    I'm completely lost. I don't want to use strings as IDs in my DB!!!!

    Can someone help me figure how is this possible??

    Thanks,
    Justin
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What does this line do:
    SelectedValue: RMABindingSourc e - RMA_NUM
    Does it change the currently selected item in the combo box to the record that is referenced in RMABindingSourc e?

    I've always used SelectedValue to retreive the value selected.



    Also, is this for a web application or a windows application?
    What does that actual code look like? It might be implicitly casting a value to a string somewhere?

    Comment

    • TonFrere
      New Member
      • Nov 2007
      • 14

      #3
      Hello, thanks for your quick reply.

      This is a Windows application.

      SelectedValue, as you said, retreive the value selected. This is why it is linked to the RMA_NUM field of the RMABindingSourc e.

      As for the code, absolutely no code is entered concerning this field (exept for Visual Studio auto-generated code) Frankly, I have no idea how to display it but you're right, the problem might be there.

      Could you give a an example of what the code for implicitly casting might look like? This could help me run through the code and look for it. I have the exact same problem with other dropdown lists. Even though I doubt being able to debug this deep of a level.

      This application is almost all drag-and-drop data-binded controls. But I must admit that I often delete and recreate datatables in the dataset designer (basicly each time I make changes to the database structure) Is there a clean way to do that?

      Thanks for your help, I'm quite desperate.
      Justin

      Originally posted by Plater
      What does this line do:
      SelectedValue: RMABindingSourc e - RMA_NUM
      Does it change the currently selected item in the combo box to the record that is referenced in RMABindingSourc e?

      I've always used SelectedValue to retreive the value selected.



      Also, is this for a web application or a windows application?
      What does that actual code look like? It might be implicitly casting a value to a string somewhere?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I've never actually used the drag and drop controls, so I don't think I can help you.
        But it's entirely possible it's treating things as a string for display purposes?

        Comment

        • TonFrere
          New Member
          • Nov 2007
          • 14

          #5
          No, since other numeric fields are correctly stored to the database.

          Thanks for your help. If I ever found an answer, I'll let you know.

          Justin

          Comment

          • TonFrere
            New Member
            • Nov 2007
            • 14

            #6
            Eureka! I'm the only one to blame... me and my love for drag'n'drop thingies.

            As a former MS Access programmer I'm used to creating controls by draging it from the datadource panel to the form and then, modifying it.

            The thing is, I dragged and droped my FAB_num field to the form as a new combobox. What I should have done, is to create the combobox by draging the FAB datatable (as a combobox) and droping it to the form. And then, link the combobox to my RMA datasource with the "Selected value" property of the combobox.

            To make a short story, if you want to create a bound combobox using the drag-and-drop features of visual studio, think about what is populating it before which field is it controling.

            Justin

            Comment

            Working...