CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Sep 2014
    Posts
    2

    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.

    Code:
    Name                eMail                                       Department
    abc                 abc@japan.com	         Production
    xyz                 xyz@uk.com		 Sales or marketing (enum)
    def                 def@germany.com	 string..can be anything as there are too many departments
    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

  2. #2
    Join Date
    Aug 2014
    Posts
    6

    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);

  3. #3
    Join Date
    Sep 2014
    Posts
    2

    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.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured