I want to use the textbox search_txt to filter my DataGridView values, such that whatever letter entered in the textbox auto completes and I am getting an error
Here's the method created
void AutoCompleteText()
{
search_txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
search_txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection coll = new AutoCompleteStringCollection();
OleDbCommand command = new OleDbCommand();
command.Connection = conDB;
command.CommandText = "select CCSpn_CODE,CCLname,CCFname,CCMname,CCDOB,CCgender,CCSchool,CaClass,CCVillage,CCSiblings,CCGuardian,CCContact,CCcurrentDt,CCImage from abaanaCC";
OleDbDataReader myreader;
try
{
conDB.Open();
myreader = command.ExecuteReader();
while (myreader.Read())
{
//Error Here!!!!!
string sName = myreader.GetString("CCLname")
coll.Add(sName);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
search_txt.AutoCompleteCustomSource = coll;
}
Here's code that loads the DataGridView
private void btnloaddata_Click(object sender, EventArgs e)
{
try
{
conDB.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conDB;
command.CommandText = "select CCSpn_CODE ,CCLname ,CCFname ,CCMname,CCDOB,CCgender,CCSchool,CaClass,CCVillage,CCSiblings,CCGuardian ,CCContact,CCcurrentDt,CCImage from abaanaCC";
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
// this.dataGridView1.Sort(this.dataGridView1.Columns["CCLname"], ListSortDirection.Ascending);
}
catch (Exception ex)
{
MessageBox.Show("Unable to Load Data");
}
conDB.Close();
}