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
Re: Question about DataGridView with ComboBox column
Quote:
Originally Posted by
kender_a
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.
Re: Question about DataGridView with ComboBox column
Quote:
Originally Posted by
JonnyPoet
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
Re: Question about DataGridView with ComboBox column
Quote:
Originally Posted by
kender_a
....
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)