I have a 'DataTable' populated with items from a SqlServer table. There are two columns in the 'DataTable': 'id' which is the identity value for the row in the SqlServer table and 'job' which is the name of an object.
I have a database client written in 'C#' using the '.Net' framework. It contains a 'ListBox', a 'TextBox', a 'DataTable', and a 'DataView'. The 'DataView' 'DataSource' is set to the 'DataTable'. The 'ListBox' 'DataSource' is set to the 'DataView'. There are 1700 rows in the table.
My preferred method of finding the correct item is for the user to begin to type in the textbox and as with each letter the list diminishes until the user can easily spot the desired one. The user can then double click on it and some action is taken. I have used this technique with 'BindingSource' and it works well. I am having trouble using with the 'DataView'. The first two letters the user types work well. But when the third letter is typed, the 'ListBox' goes blank, even though the filter string is correct. Why does it stop working with the third letter? Any help would be appreciated.
This is a sample of the data in the field 'job': '08-CBM-01 -- Water Utilities Topo Survey' The data in the field 'id' is just an 'int' identity from SqlServer.
I've tried examining the variable strLookup and strFilter as entry is made using the keyboard and it appears these are correct.
DataTable tblSelectList;
DataView dvSelectList;
private string strFilter = "";
private string strLookup = "";
private void tbLookup_TextChanged(object sender, EventArgs e)
{
strLookup = tbLookup.Text.ToString();
if (strLookup.Length > 1)
{
strFilter = "job Like '%" + strLookup + "%'";
dvSelectList.RowFilter = strFilter;
}
else { dvSelectList.RowFilter = "job = 'z'"; }
btnDone.Enabled = false;
}
private void SetupLbSelect()
{
if (dvSelectList == null) { dvSelectList = new DataView(tblSelectList); }
lbSelect.DataSource = dvSelectList;
dvSelectList.RowFilter = "job = 'z'";
lbSelect.DisplayMember = "job";
lbSelect.ValueMember = "id";
}
No error messages. The ListBox begins to populate as expected with the 1st two characters and then goes blank with the third. I would expect to type 'Topo' and have all the items containing 'Topo' appear.
if (strLookup.Length > 0)instead of> 1. - LarsTech