I am trying to change the datagridview row selection base on the value inputted in textbox with suggestappend. My autocompletestringcollection was fetched on my datagrid column reference.
Code for autocompletestringcollection
AutoCompleteStringCollection referenceCollection = new AutoCompleteStringCollection();
int indexOfYourColumn = 1;
IList list = dgvScriptures.Rows;
referenceCollection.Clear();
for (int i = 0; i < list.Count; i++)
{
DataGridViewRow row = (DataGridViewRow)list[i];
data = row.Cells[indexOfYourColumn].Value.ToString();
referenceCollection.Add(data.ToString());
}
When type in textbox, value is appended but the datagridview selection was not changed
private void txtSearchReference_TextChanged(object sender, EventArgs e)
{
try
{
txtSearchReference.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtSearchReference.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtSearchReference.AutoCompleteCustomSource = referenceCollection;
if (txtSearchReference.Text != string.Empty)
{
int rowIndex = -1;
DataGridViewRow row = dgvScriptures.Rows
.Cast<DataGridViewRow>()
.Where(r => r.Cells[1].Value.ToString().Contains(txtSearchReference.Text))
.FirstOrDefault();
rowIndex = row.Index;
dgvScriptures.Rows[rowIndex].Selected = true;
}
}
catch (Exception autocomplete)
{
MessageBox.Show(autocomplete.ToString());
}
}