如何在网格视图中访问Combobox列?

发布于 2025-01-31 04:55:39 字数 1286 浏览 1 评论 0原文

抱歉,如果我的问题可能有些混乱。我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荭秂 2025-02-07 04:55:39

看来我找到了我以前问题的解决方案,也许这可以帮助那些有同样问题的人,或者也许比这更简洁或更好的程序代码?
这是固定的代码,它对我有用,只是添加了几行:

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;
            }

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;
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文