Question about DataGridView with ComboBox column
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Question about DataGridView with ComboBox column

Hybrid View

  1. #1

    Question Question about DataGridView with ComboBox column

    Folks,

    Iím making a dialog which has a DataGridView bound to a simple XML file through a DataSet. The first column in the grid is a ComboBox type. The ComboBox has a set of numbers based on the immediate input. The set in the ComboBox may change from time to time, and the value stored in the XML may no longer be a part of the set**. When that happens, I get a DataError event and ArgumentException. What would be the best way to handle that? Of course, I can just ignore all ArgumentException, but I donít feel that that would be the best practice.

    ** Thatís not abnormal. The operator is expected to pick a value from the new set.

    Cheers,
    - Nick

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: Question about DataGridView with ComboBox column

    Quote Originally Posted by kender_a View Post
    Folks,

    Iím making a dialog which has a DataGridView bound to a simple XML file through a DataSet. The first column in the grid is a ComboBox type. The ComboBox has a set of numbers based on the immediate input. The set in the ComboBox may change from time to time, and the value stored in the XML may no longer be a part of the set**. When that happens, I get a DataError event and ArgumentException. What would be the best way to handle that? Of course, I can just ignore all ArgumentException, but I donít feel that that would be the best practice.

    ** Thatís not abnormal. The operator is expected to pick a value from the new set.

    Cheers,
    - Nick
    That would depend on what you want to get done when this occurs. Should the user be informed, should the set be extened for that case. The first question you have to decide is what you expect from your application it should do. Then you can decide in which way this may be done.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3

    Re: Question about DataGridView with ComboBox column

    Quote Originally Posted by JonnyPoet View Post
    The first question you have to decide is what you expect from your application it should do.
    Yes, of course. Sorry, I didn't make it clear in the initial post. Here's the scenario:

    1. The application is launched for the 1st time. The XML file that persists the information is empty.
    1.1 The ComboBox lists within the DataGridView are populated based on what devices are currently plugged into USB (medical devices that I'm designing). Say, 1 and 2.
    1.2 The user makes his choice in the ComboBox. Say, 1. Clicks OK.
    1.3 Application saves the choice to the XML file and proceeds with its main function.

    2. The application is launched again later. This time, a different set of devices is connected to the USB. Say, 2 and 3. I want to present a blank ComboBox to the user. He'll make a new choice.
    2.1 The ComboBox lists within the DataGridView are populated based on what devices are currently plugged in. This time it's 2 and 3.
    2.2 DataSet reads the XML file and tries updates the DataGridView. Since 1 is not available in the ComboBox in the DataError event with ArgumentException is generated. Question is - what's the best way to handle it?

    Any insight will be greatly appreciated!

    - Nick
    Last edited by kender_a; July 7th, 2009 at 10:26 PM.

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: Question about DataGridView with ComboBox column

    Quote Originally Posted by kender_a View Post
    ....
    2.1 The ComboBox lists within the DataGridView are populated based on what devices are currently plugged in. This time it's 2 and 3.
    2.2 DataSet reads the XML file and tries updates the DataGridView. Since 1 is not available in the ComboBox in the DataError event with ArgumentException is generated. Question is - what's the best way to handle it? ...
    Precheck the situation before the combobox is filled. Obviously the combobox is filled with corect data. And then you are reading the XML file via Dataset and updating the actual entry of the selected value. I'm right ?
    This case I would suggest don't use binding but simple read the XML dataset and check if your value is still available. If yes choose the selection if no shiow a message on screen that the user has to choose a new value.

    Basically you shouldn't read from an XML file which is not up to date. An other maybe complex way would be that when changing the stick, your progam should be aware that the stick was changed and refresh / delete the unapplicabele data in your XML file. Maybe you can have a method watching the USB ports and fireing an event when this happens ( typically watching would be done in a backgroundthread IMHO)
    Last edited by JonnyPoet; July 8th, 2009 at 02:49 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center