在datagridview标头单元上自动过滤 [英] autofilter on datagridview headercell
问题描述
我想在Windows的datagridview控件的标题单元格中显示自动筛选"下拉按钮.
这就是我所拥有的:
I would like to display the AutoFilter drop-down button in a header cell of the windows''s datagridview control.
This is what I have:
DataTable dt = new DataTable();
dt = DataGet();
if (dt.Rows.Count > 0)
{
DataView defaultView = dt.DefaultView;
dgv.DataSource = null;
dgv.DataSource = defaultView;
}
dgv.Columns["Surnames"].HeaderCell = new DataGridViewAutoFilterColumnHeaderCell();
上面的这一行给出了以下错误.
你知道如何解决吗?
请注意,我不想在设计时创建datagridview的字段,因为正如您在这段代码中所看到的,它们会自动添加到datagridview中.
谢谢
{包含的DataGridView控件的DataSource属性必须设置为BindingSource."} System.Exception
This above line gives the following error.
Do you know how this can be solved please?
Note that I do not want to create the fields of the datagridview at design time because as you see in this code, they get added automatically to the datagridview.
Thanks
{"The DataSource property of the containing DataGridView control must be set to a BindingSource."} System.Exception
{System.NotSupportedException}
推荐答案
已解决.感谢您的回答.
Solved. Thanks for the answer.
这篇关于在datagridview标头单元上自动过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!