-
September 21st, 2014, 09:02 AM
#1
DataTable with mixed datatypes in same column
Hi,
I am designing a DataGrid in WPF which is conneced (binding) with a specific DataTable. Below is requirement and am unable to resolve it.
The DataTable has 3 columns namely: Name, Email, Department
Depending on the email address of the employee (which also tells the category of deparment), the department is either an enum of type1 or type2 or its a string.
Now how to change datatype of a particular column at runtime depending upon the domain entered by the user in email address?? Is it possible at all?
regards
AA
-
September 22nd, 2014, 05:50 AM
#2
Re: DataTable with mixed datatypes in same column
Store a string in "Department" column, and cast it to the appropriate enum when reading data from DataTable.
EnumType enumValue = (EnumType)Enum.Parse(typeof(EnumType), stringValue, true);
-
September 22nd, 2014, 12:53 PM
#3
Re: DataTable with mixed datatypes in same column
I am sure that I wasn't able to explain my requirement correctly.
The user shall be able to choose from the column "Department" using a combo-box (list) when i.e. sales or marketing if he/she enters Email address with uk domain and shall be able to write anything if Germany is entered. A combo-box is shown automatically in column when the column type is enum but when it is string then its not possible. A column can be either string or enum_1 type or enum_2 type. I want that it shall be of type "enum_1" for first row, of "enum_2 for second row and of "string" for third row.
-
September 26th, 2014, 05:14 PM
#4
Re: DataTable with mixed datatypes in same column
Instead of binding to a DataTable, the grid should bind to a ViewModel. In there you will create properties that correctly expose data for the grid.
In short you can't bind the DataTable directly - you need an intermediary layer to expose the data as needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|