We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

AutoComplete.DataSource - Reset technique

I have the following code which runs normally the first time it is invoked but fails on any subsequent call. (User is selecting a field name sans '_' in one combo box, a textbox with an autofill needs to be changed as a result...) The ArrayList() is clean.... What did I miss? 'Invoked when a combo box specifying a valid column is changed to re-populate autocomplete lookup list Private iTotalRowCount As Integer, iRowCount As Integer, m_LastItem As String, m_TempItem As String Public Sub FillAutoCompleteListByColName(ByVal dv As DataView, ByVal sColName As String, ByRef AutoCtl As Syncfusion.Windows.Forms.Tools.AutoComplete) Dim tmpArray As New ArrayList() sColName = sColName.Replace(" ", "_") dv.Sort = sColName m_LastItem = String.Empty iTotalRowCount = dv.Count If iTotalRowCount > 0 Then For iRowCount = 0 To iTotalRowCount - 1 If (dv(iRowCount).Item(sColName).ToString <> String.Empty) Then m_TempItem = dv(iRowCount).Item(sColName).ToString If m_TempItem <> m_LastItem Then tmpArray.Add(m_TempItem) m_LastItem = m_TempItem End If End If Next End If Try AutoCtl.DataSource = tmpArray ' Line 202 above Catch E As Exception 'MsgBox(E.ToString) Console.WriteLine(E.ToString) End End Try 'Runs fine first time, autocomplete works great... Second time (or any subsequent) I see... Syncfusion.Windows.Forms.Tools.DataSourceException: There was a problem with the specified DataSource. Please check the InnerException for more details. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos) at System.Data.DataTable.AddRow(DataRow row, Int32 proposedID) at System.Data.DataRowCollection.Add(DataRow row) at Syncfusion.Windows.Forms.Tools.AutoComplete.SetTableData() --- End of inner exception stack trace --- at Syncfusion.Windows.Forms.Tools.AutoComplete.SetTableData() at Syncfusion.Windows.Forms.Tools.AutoComplete.set_DataSource(Object value) at TargetTrak_Pro.QuickFilter.FillAutoCompleteListByColName(DataView dv, String sColName, AutoComplete& AutoCtl) in C:\Documents and Settings\Sam\My Documents\Visual Studio Projects\TargetTrak_Pro\QuickFilter.vb:line 202 The program '[3096] TargetTrak_Pro.exe' has exited with code 0 (0x0).

2 Replies

SH Sam Horton July 24, 2002 07:17 AM

> I have the following code which runs normally the first time it is invoked but fails on any subsequent call. (User is selecting a field name sans '_' in one combo box, a textbox with an autofill needs to be changed as a result...) > > The ArrayList() is clean.... What did I miss? > > 'Invoked when a combo box specifying a valid column is changed to re-populate autocomplete lookup list > Private iTotalRowCount As Integer, iRowCount As Integer, m_LastItem As String, m_TempItem As String > Public Sub FillAutoCompleteListByColName(ByVal dv As DataView, ByVal sColName As String, ByRef AutoCtl As Syncfusion.Windows.Forms.Tools.AutoComplete) > Dim tmpArray As New ArrayList() > sColName = sColName.Replace(" ", "_") > dv.Sort = sColName > m_LastItem = String.Empty > > iTotalRowCount = dv.Count > If iTotalRowCount > 0 Then > For iRowCount = 0 To iTotalRowCount - 1 > If (dv(iRowCount).Item(sColName).ToString <> String.Empty) Then > m_TempItem = dv(iRowCount).Item(sColName).ToString > If m_TempItem <> m_LastItem Then > tmpArray.Add(m_TempItem) > m_LastItem = m_TempItem > End If > End If > Next > End If > > Try > AutoCtl.DataSource = tmpArray > ' Line 202 above > Catch E As Exception > 'MsgBox(E.ToString) > Console.WriteLine(E.ToString) > End > End Try > > 'Runs fine first time, autocomplete works great... Second time (or any subsequent) I see... > > Syncfusion.Windows.Forms.Tools.DataSourceException: There was a problem with the specified DataSource. Please check the InnerException for more details. ---> System.NullReferenceException: Object reference not set to an instance of an object. > at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos) > at System.Data.DataTable.AddRow(DataRow row, Int32 proposedID) > at System.Data.DataRowCollection.Add(DataRow row) > at Syncfusion.Windows.Forms.Tools.AutoComplete.SetTableData() > --- End of inner exception stack trace --- > at Syncfusion.Windows.Forms.Tools.AutoComplete.SetTableData() > at Syncfusion.Windows.Forms.Tools.AutoComplete.set_DataSource(Object value) > at TargetTrak_Pro.QuickFilter.FillAutoCompleteListByColName(DataView dv, String sColName, AutoComplete& AutoCtl) in C:\Documents and Settings\Sam\My Documents\Visual Studio Projects\TargetTrak_Pro\QuickFilter.vb:line 202 > The program '[3096] TargetTrak_Pro.exe' has exited with code 0 (0x0). --update-- I have this working in a slightly different form, but if you have any recc. for an improvement or overlooked best approach I would appreciate the advice....... Private iTotalRowCount As Integer, iRowCount As Integer, m_LastItem As String, m_TempItem As String Public Sub FillAutoCompleteListByColNameWithBind(ByVal dv As DataView, ByVal sColName As String, ByRef bindTxtBox As Windows.Forms.TextBox) Dim tmpArray As New ArrayList() sColName = sColName.Replace(" ", "_") dv.Sort = sColName m_LastItem = String.Empty iTotalRowCount = dv.Count If iTotalRowCount > 0 Then For iRowCount = 0 To iTotalRowCount - 1 If (dv(iRowCount).Item(sColName).ToString.Trim <> String.Empty) Then m_TempItem = dv(iRowCount).Item(sColName).ToString If m_TempItem <> m_LastItem Then tmpArray.Add(m_TempItem) m_LastItem = m_TempItem End If End If Next End If tmpArray.TrimToSize() Try Dim newAutoCtl As New Syncfusion.Windows.Forms.Tools.AutoComplete() newAutoCtl.AutoSerialize = False newAutoCtl.BorderType = Syncfusion.Windows.Forms.Tools.AutoCompleteBorderTypes.Sizable newAutoCtl.CategoryName = sColName newAutoCtl.DataSource = tmpArray newAutoCtl.SetAutoComplete(bindTxtBox, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.AutoSuggest) Catch E As Exception 'MsgBox(E.ToString) Console.WriteLine(E.ToString) End End Try End Sub


DJ Davis Jebaraj Syncfusion Team July 26, 2002 03:01 PM

Hi Sam, I will see what can be done to prevent this problem and get back to you. Thank you for your patience. Regards, Davis

Loader.
Live Chat Icon For mobile
Up arrow icon