This is a migrated thread and some comments may be shown as answers.

Formatstring on dynamic datasource not working

3 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 07 Jul 2016, 12:43 PM

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.

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Jul 2016, 08:38 AM
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.
0
Mike
Top achievements
Rank 1
answered on 08 Jul 2016, 10:48 AM

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.

0
Dimitar
Telerik team
answered on 12 Jul 2016, 09:19 AM
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.
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Mike
Top achievements
Rank 1
Share this question
or