Formatstring on dynamic datasource not working

4 posts, 0 answers
  1. Mike
    Mike avatar
    2 posts
    Member since:
    Mar 2015

    Posted 07 Jul Link to this post

    I'm trying to change the datasource for a template as follows

    Dim ContactPhonesDS As ContactsDataset.PhoneRow() = ContactsDataset.Phone.Select("ContactKey = '" & ContactKey & "'")
              Dim ContactDt As DataTable = New DataTable("Phone")
              ContactDt.Columns.Add("TableKey")
              ContactDt.Columns.Add("ContactKey")
              ContactDt.Columns.Add("Client_ID")
              ContactDt.Columns.Add("Office_ID")
              ContactDt.Columns.Add("PRNumber")
              ContactDt.Columns.Add("Line_Type")
              ContactDt.Columns.Add("comboLine_Type")
              ContactDt.Columns.Add("Phone_Number")
              ContactDt.Columns.Add("Extension")
              ContactDt.Columns.Add("Discription")
              ContactDt.Columns.Add("Delete_Flag")
              For Each row In ContactPhonesDS
                  ContactDt.ImportRow(row)
              Next
              PHNumbers.MasterTemplate.DataSource = ContactDt
              PHNumbers.MasterTemplate.Columns("Phone_Number").FormatString = "{0:(000)000-0000}"

    But the formatstring is not applied. I'm Guessing it's because the column is not of the correct data type, but I can't figure out how to set it to decimal.

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 08 Jul Link to this post

    Hi Mike,

    Thank you for writing.

    You can set the data type when the columns are added to the table:
    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
    table.Columns.Add("Drug", typeof(string));
    table.Columns.Add("Name", typeof(string));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("Bool", typeof(bool));

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    2 posts
    Member since:
    Mar 2015

    Posted 08 Jul in reply to Dimitar Link to this post

    Thankyou. I had tried your suguest, but it gives me compiler errors. I was however able to find the correct format for the add command. It is...

    ContactDt.Columns.Add("TableKey", GetType(System.Int64))
    ContactDt.Columns.Add("ContactKey", GetType(System.Int64))
    ContactDt.Columns.Add("Client_ID", GetType(System.Int32))
    ContactDt.Columns.Add("Office_ID", GetType(System.Int32))
    ContactDt.Columns.Add("PRNumber", GetType(System.Int32))
    ContactDt.Columns.Add("Line_Type")
    ContactDt.Columns.Add("Phone_Number", GetType(System.Int64))
    ContactDt.Columns.Add("Extension", GetType(System.Int32))
    ContactDt.Columns.Add("Discription", GetType(System.String))
    ContactDt.Columns.Add("Delete_Flag", GetType(System.Boolean))

    Again than you for the response.

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 12 Jul Link to this post

    Hello Mike,

    I forgot to convert the code to Visual Basic. Nevertheless, I am glad that you have found a solution for your case. 

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top