473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How can we put autosuggest combobox in datagridview column1

Hi Guys,

Suppose I put one combobox in first column of datagrid,
then How can we made combobox act as a autosuggest from access 2007 database only,


Please help me,


Regard's
Ankit
May 10 '10 #1

✓ answered by ThatThatGuy

you can try this snippet....i worked it on and it worked for me...
in DataGridView.EditingControlShowing event
Expand|Select|Wrap|Line Numbers
  1.             if (e.Control is DataGridViewComboBoxEditingControl)
  2.             {
  3.                ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
  4.               ((ComboBox)e.Control).AutoCompleteCustomSource.AddRange(new string[] { "apple", "bat", "cat", "doggie" });
  5.               ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
  6.                ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  7.  
  8.             }
  9.  

4 5351
ThatThatGuy
449 Expert 256MB
have you tried the properties AutoCompleteCustomSource,AutoComplete mode,AutoCompleSource properties of a combobox
May 10 '10 #2
@ThatThatGuy
Yes I was already use that,
but its not working,

Please just check it at once with my snippet in which I was trying to put autosuggest text box only:-


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


namespace DatagridExample
{
public partial class Form1 : Form
{
AutoCompleteStringCollection scAutoComplete = new AutoCompleteStringCollection();

public Form1()
{
//AutoCompleteStringCollection scAutoComplete = new AutoCompleteStringCollection();

InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string strCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DBAccount.accdb";
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection conn = new OleDbConnection();
DataSet ds = new DataSet();
conn = new OleDbConnection(strCon);

da = new OleDbDataAdapter("Select *from Bill", conn);
da.Fill(ds, "Bill");


dataGridView1.DataSource = ds.Tables("Bill");


OleDbCommand cmd = new OleDbCommand("Select ItmCode from Bill", conn);
OleDbDataReader reader = new OleDbDataReader();
OleDbDataReader dr = new OleDbDataReader();
conn.Open();
dr = cmd.ExecuteReader;
while (dr.Read)
{
scAutoComplete.Add(dr.GetString(0));

}
conn.Close();



}


private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1 && e.Control is TextBox)
{
((TextBox)e.Control).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
((TextBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
((TextBox)e.Control).AutoCompleteCustomSource = scAutoComplete;
}
}
}
}
====================================
I got some error on these below line:-

1. dataGridView1.DataSource = ds.Tables("Bill");

" Error 1 Non-invocable member 'System.Data.DataSet.Tables' cannot be used like a method."


2. OleDbDataReader dr = new OleDbDataReader();
("Error 2 The type 'System.Data.OleDb.OleDbDataReader' has no constructors define ")


please help in this snippet............
May 10 '10 #3
ThatThatGuy
449 Expert 256MB
you can try this snippet....i worked it on and it worked for me...
in DataGridView.EditingControlShowing event
Expand|Select|Wrap|Line Numbers
  1.             if (e.Control is DataGridViewComboBoxEditingControl)
  2.             {
  3.                ((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
  4.               ((ComboBox)e.Control).AutoCompleteCustomSource.AddRange(new string[] { "apple", "bat", "cat", "doggie" });
  5.               ((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.CustomSource;
  6.                ((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
  7.  
  8.             }
  9.  
May 10 '10 #4
@ThatThatGuy
Thanks it works now,
May 10 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: | last post by:
Hi all, Any one know that how to add combobox in datagrid or any 3rd party datagrid can do that.. Thanks
0
by: Mark Carew | last post by:
Hi, I'm writing a winform app (as practice) that has as one of its features a button that reads an xml file to a datagridview. No matter what I do I get two columns instead of one. The...
6
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
3
by: steve | last post by:
Hi All How can I get the datagridview to redraw after changing the rowtemplate.height at runtime ( it is databound to a datatable) I have tried datagridview1.refresh etc to no avail (The row...
8
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
4
by: Terry Olsen | last post by:
How can i tell if a row in my DataGridView has been edited? I'm loading a DataTable with ID3 information from MP3 files and using that as the datasource for the DataGridView. I'm letting the user...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
1
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, I have an DataGridView control with the following columns (added using the designer): column1 - DataGridViewTextBoxColumn column2 - DataGridViewComboBoxColumn (values "test1", "test2")...
6
by: naseemsadak | last post by:
Hi, I'm developing a program in c# 2005 and would like to know if it is possible to refresh a tab page's controls(e.g textboxes, combobox, datagridview) when a different tab is selected so when i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.