Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
491
FormatException when binding UltraCombo with UltraDatasource
posted

 

Hi,

Today, after reading the post of Mike about Grid Performance Guide, I have tried to checked all the Debug Exceptions of Visual studio to prevent performance problems about wrong datatype. 

Immediatly after activating this Exceptions, I open one of my project and "Bang", a FormatException has been throw a couple of time in one of my form.

After searching for a couples of hours, I have detected that the problem is on the UltraCombo bind with an UltraDataSource.

When I attach an UltraDataSource with a column of type Integer linked with the ValueMember, exception are throw; FormatException from Infragistics.

When the type of the column is String, no problem.

I have created a sample project linked with this post to show you exactly the problem with the UltraCombo.

Thank you for your help.

 

"Sorry, this is the message that I received when I try to send you my project"

Sorry, there was a problem with your last request!

Either the site is offline or an unhandled error occurred. We apologize and have logged the error. Please try your request again or if you know who your site administrator is let them know too.

 

For this reason, here is the code that I have created in the project: As you will see, this is very simple and it throw exceptions when you have checked exception for Common Language Runtime Exceptions in Visual studio.

 

  Private Sub cboLoadWithUltraDataSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLoadWithUltraDataSource.Click

      Dim stopWatch As New System.Diagnostics.Stopwatch

 

      stopWatch.Start()

 

      Dim dataSource As New Infragistics.Win.UltraWinDataSource.UltraDataSource

 

      dataSource.Band.Columns.Add("Id", GetType(Integer))

      dataSource.Band.Columns.Add("Text", GetType(String))

 

      For i As Integer = 1 To 100

         Dim row As Infragistics.Win.UltraWinDataSource.UltraDataRow

 

         row = dataSource.Rows.Add()

 

         row.SetCellValue("Id", i)

         row.SetCellValue("Text", "Item" & i.ToString)

      Next

 

      cboItems.ValueMember = "Id"

      cboItems.DisplayMember = "Text"

 

      cboItems.DataSource = dataSource

 

      stopWatch.Stop()

      lblElapsedTime.Text = stopWatch.ElapsedMilliseconds.ToString & "milliseconds"

 

      cboItems.PerformAction(Infragistics.Win.UltraWinGrid.UltraComboAction.Dropdown)

   End Sub

 

   Private Sub cboLoadWithDataTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLoadWithDataTable.Click

      Dim stopWatch As New System.Diagnostics.Stopwatch

 

      stopWatch.Start()

 

      Dim table As New System.Data.DataTable

 

      table.Columns.Add("Id", GetType(Integer))

      table.Columns.Add("Text", GetType(String))

 

      For i As Integer = 1 To 100

         Dim newRow As System.Data.DataRow

 

         newRow = table.NewRow

         newRow.Item("Id") = i

         newRow.Item("Text") = "Item" & i.ToString

         table.Rows.Add(newRow)

      Next

 

      cboItems.ValueMember = "Id"

      cboItems.DisplayMember = "Text"

 

      cboItems.DataSource = table

 

      stopWatch.Stop()

      lblElapsedTime.Text = stopWatch.ElapsedMilliseconds.ToString & "milliseconds"

 

      cboItems.PerformAction(Infragistics.Win.UltraWinGrid.UltraComboAction.Dropdown)

   End Sub

 

   Private Sub cboLoadWithUltraDataSourceNoException_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLoadWithUltraDataSourceNoException.Click

      Dim stopWatch As New System.Diagnostics.Stopwatch

 

      stopWatch.Start()

 

      Dim dataSource As New Infragistics.Win.UltraWinDataSource.UltraDataSource

 

      dataSource.Band.Columns.Add("Id", GetType(String))

      dataSource.Band.Columns.Add("Text", GetType(String))

 

      For i As Integer = 1 To 100

         Dim row As Infragistics.Win.UltraWinDataSource.UltraDataRow

 

         row = dataSource.Rows.Add()

 

         row.SetCellValue("Id", i.ToString)

         row.SetCellValue("Text", "Item" & i.ToString)

      Next

 

      cboItems.ValueMember = "Id"

      cboItems.DisplayMember = "Text"

 

      cboItems.DataSource = dataSource

 

      stopWatch.Stop()

      lblElapsedTime.Text = stopWatch.ElapsedMilliseconds.ToString & "milliseconds"

 

      cboItems.PerformAction(Infragistics.Win.UltraWinGrid.UltraComboAction.Dropdown)

   End Sub

 

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    Sorry about that, there must have been a temporary problem with our forums. If you want to try re-attaching the sample, I will be happy to take a look at it.

    I used the code you have here to put together a sample, and I do see some FormatExceptions by default, because the default Text on the UltraCombo is "UltraCombo1" and this text does not exist on the list you are building.

    So when you drop down the list, the combo tries to convert it's current text into a DataValue on the list so that it can search the list and find the matching item to highlight. It fails to do so and so (because "UltraCombo1" is not on the list, and so it tries to convert the text into the appropriate data type for the value (integer in this case). This is where the exceptions occurs.

    This particular case is not really a big deal in terms of performance, because it's a few exceptions that occur in response to a single use action - dropping down the combo. So the slowdown from something like this will not be noticable to the user. It's only when handled exceptions occur during automated operations in large groups that they become noticable.

Children
No Data