Hi
I have gridview with 2 column (Group Name,ProductName).
I have used following code for autocomplete bt it doesnt work:
At Form Load:
setAutoComplete();
private void setAutoComplete()
{
try
{
SqlDataReader dReader;
SqlCommand cmd = new SqlCommand();
cmd.Connection = oDAL.OpenConnection();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select PNAME from tbl_Master_Product ";
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader[0].ToString());
}
dReader.Close();
oDAL.CloseConnection();
cmd.Dispose();
}
catch (Exception EX)
{
}
}
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
private void DGVDetails_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
if (e.Control is DataGridViewComboBoxEditingControl)
{
if (DGVDetails.CurrentCell.ColumnIndex == 5)
{
((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
((ComboBox)e.Control).AutoCompleteCustomSource = namesCollection;
}
else
{
prodCode.AutoCompleteMode = AutoCompleteMode.None;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
It is working properly when iam using textbox in place of comboobx.
& my 2nd question is how should i display respective product when i click group name.
For eg:
If i click Nokia in group name then in Product name combobox column only nokia products should be diplayed which are stored at group master table
Loading

Hemant KumarPosted Oct 28, 2011, 1:20 AM
private string[] list;
private DataSet ds;
public frmMain()
{
InitializeComponent();
ds = this.GetDataSet("SELECT deptName from empDept", "empDept");
list = new string[ds.Tables[0].Rows.Count];
comboBox1.AutoCompleteCustomSource.AddRange(list);
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is ComboBox)
{
ComboBox cb = e.Control as ComboBox;
cb.DropDownStyle = ComboBoxStyle.DropDown;
}
}
refer this example also
http://www.sourcecodester.com/visual-basic-net/autocomplete-combobox-datagridview-control.html
If this is helpful
{ Please Mark as Answered }
else if it is not helpful
{ Un-Mark as Answered }
Hemant KumarPosted Oct 30, 2011, 11:13 AM
Pravin GhadgePosted Oct 29, 2011, 11:31 PM
Prabhu RajaPosted Oct 28, 2011, 2:40 AM
Try this attached Source Code.