Hi everybody, I have a trouble with ArgumentOutOfRa ngeException. When I type a French word in an AutoCompleteCom boBox then submit it to add new record to database, the combo box throw an exception:
ArgumentOutOfRa ngeException was unhandled:
InvalidArgument =Value of '0' is not valid for 'index'.
Parameter name: index
This exception appears in line:
addr = cboAddr.Text;
And here's the code of AutoCompleteCom boBox class:
Can somebody help me?? Is there anything wrong with my AutoCompleteCom boBox??
Thanks in advanced!
ArgumentOutOfRa ngeException was unhandled:
InvalidArgument =Value of '0' is not valid for 'index'.
Parameter name: index
This exception appears in line:
addr = cboAddr.Text;
And here's the code of AutoCompleteCom boBox class:
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.ComponentModel; using System.Data.OleDb; using System.Data.DataSetExtensions; using System.Data; namespace WindowsFormsApplication1 { public class AutoCompleteComboBox : System.Windows.Forms.ComboBox { public event System.ComponentModel.CancelEventHandler NotInList; //private bool _limit; private bool _limitToList = true; private bool _inEditMode = false; public AutoCompleteComboBox() : base() { } public bool LimitToList { get { return _limitToList; } set { _limitToList = value; } } protected virtual void OnNotInList(System.ComponentModel.CancelEventArgs e) { if (NotInList != null) { NotInList(this, e); } } protected override void OnTextChanged(System.EventArgs e) { if (_inEditMode) { string input = Text; int i; //int index = FindString(input); while (this.Items.Count > 0) { this.Items.RemoveAt(0); } this.DroppedDown = true; Controldb db = new Controldb(); DataTable myTable = new DataTable(); string combox_text = this.Text; string query = ""; query = "SELECT DISTINCT adresse FROM tblMain WHERE trans = 'in' AND " + "adresse LIKE '%" + combox_text + "%'"; try { myTable = db.getTable(query); } catch (Exception e1) { MessageBox.Show(e1.ToString()); } if (myTable.Rows.Count > 0) { foreach (DataRow myDataRow in myTable.Rows) { this.Items.Add(myDataRow["adresse"].ToString()); } } } base.OnTextChanged(e); } protected override void OnValidating(System.ComponentModel.CancelEventArgs e) { if (this.LimitToList) { int pos = this.FindStringExact(this.Text); if (pos == -1) { OnNotInList(e); } else { this.SelectedIndex = pos; } } base.OnValidating(e); } protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { _inEditMode = (e.KeyCode !=Keys.Up && e.KeyCode != Keys.Down); base.OnKeyDown(e); } } }
Can somebody help me?? Is there anything wrong with my AutoCompleteCom boBox??
Thanks in advanced!
Comment