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
560
UltraComboEditor.Items.IndexOf() is throwing an exception.
posted

The IndexOf method of the Items property of an UltraComboEditor is not finding an item that is obviously in the ComboEditor.  An index of -1 is being returned.

Here is some test code:

Form File:

Public Class Form1

Private Sub UltraButton1_Click(sender As Object, e As EventArgs) Handles UltraButton1.Click

Const f As String = "first"

Const s As String = "second"

Me.UltraComboEditor1.Items.Add(f)

Me.UltraComboEditor1.Items.Add(s)

Console.WriteLine(Me.UltraComboEditor1.Items.Count)

Console.WriteLine("Item-1: " + Me.UltraComboEditor1.Items(1).DataValue.ToString() + " " + Me.UltraComboEditor1.Items(1).DisplayText)

Try

Dim index As String = Me.UltraComboEditor1.Items.IndexOf(s)

Console.WriteLine("Index: " + index.ToString())

Catch ex As Exception

Console.WriteLine(e.ToString())

End Try

End Sub

End Class

---------------------------------------

Designer File:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class Form1

Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

Try

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

Finally

MyBase.Dispose(disposing)

End Try

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

Me.UltraComboEditor1 = New Infragistics.Win.UltraWinEditors.UltraComboEditor()

Me.UltraButton1 = New Infragistics.Win.Misc.UltraButton()

CType(Me.UltraComboEditor1,System.ComponentModel.ISupportInitialize).BeginInit

Me.SuspendLayout

'

'UltraComboEditor1

'

Me.UltraComboEditor1.Location = New System.Drawing.Point(57, 32)

Me.UltraComboEditor1.Name = "UltraComboEditor1"

Me.UltraComboEditor1.Size = New System.Drawing.Size(144, 21)

Me.UltraComboEditor1.TabIndex = 0

'

'UltraButton1

'

Me.UltraButton1.Location = New System.Drawing.Point(126, 172)

Me.UltraButton1.Name = "UltraButton1"

Me.UltraButton1.Size = New System.Drawing.Size(75, 23)

Me.UltraButton1.TabIndex = 1

Me.UltraButton1.Text = "UltraButton1"

'

'Form1

'

Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Me.ClientSize = New System.Drawing.Size(284, 262)

Me.Controls.Add(Me.UltraButton1)

Me.Controls.Add(Me.UltraComboEditor1)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.UltraComboEditor1,System.ComponentModel.ISupportInitialize).EndInit

Me.ResumeLayout(false)

Me.PerformLayout

End Sub

Friend WithEvents UltraComboEditor1 As Infragistics.Win.UltraWinEditors.UltraComboEditor

Friend WithEvents UltraButton1 As Infragistics.Win.Misc.UltraButton

End Class

Output from the code:

2

Item-1: second second

Index: -1