如何在网格视图中访问Combobox列?
抱歉,如果我的问题可能有些混乱。我正在使用Telerik R1 2020,如何通过列名访问radgridview
中的ComboBox?我正在使用MySQL数据库中的radgridview
创建自动完成,但是看来我的代码在所有列中都可以使用,我只想列0
以显示自动完成。
这是我的代码片段:
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;
}
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.
This is my code snippet:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我找到了我以前问题的解决方案,也许这可以帮助那些有同样问题的人,或者也许比这更简洁或更好的程序代码?
这是固定的代码,它对我有用,只是添加了几行:
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 :