Sorry if my question might be a little confusing. I'm using telerik R1 2020, how can I access the combobox in Radgridview
by column name? I am creating autocomplete in radgridview
using MySQL database, but it seems my code is working for all columns, I just want column 0
to show autocomplete.
private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
string mainconn = ConfigurationManager.ConnectionStrings["GreatRetail_connect"].ConnectionString;
MySqlConnection mysqlconn = new MySqlConnection(mainconn);
string sqlquery = "SELECT Product_name FROM tb_stock_product";
MySqlCommand sqlcmd = new MySqlCommand(sqlquery, mysqlconn);
mysqlconn.Open();
MySqlDataAdapter sdr = new MySqlDataAdapter(sqlcmd);
DataTable dt = new DataTable();
sdr.Fill(dt);
RadDropDownListEditor listEditor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
if (listEditor == null)
{
return;
}
RadDropDownListEditorElement editorElement = listEditor.EditorElement as RadDropDownListEditorElement;
editorElement.DataSource = dt;
editorElement.DisplayMember = "Product_name";
editorElement.ValueMember = "Product_name";
editorElement.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
editorElement.DropDownStyle = RadDropDownStyle.DropDown;
}
Looks like I've found the solution to my previous question, maybe this can help those of you who have the same problem, or maybe there is a more concise or better program code than this?
this is the fixed code and it worked for me, just slightly adding a few lines:
if (sender is GridViewEditManager)
if (((GridViewEditManager)sender).GridViewElement.CurrentColumn.Name == "column1")
{
RadDropDownListEditor listEditor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
if (listEditor == null)
{
return;
}
RadDropDownListEditorElement editorElement = listEditor.EditorElement as RadDropDownListEditorElement;
editorElement.DataSource = dt;
editorElement.DisplayMember = "Product_name";
editorElement.ValueMember = "Product_name";
editorElement.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
editorElement.DropDownStyle = RadDropDownStyle.DropDown;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.