使用用户控件弹出窗口进行过滤器绑定 [英] Using User Control popup for filter bindingSource
问题描述
我有一个用户控件,其中有一个checkedListBox和一个按钮.我在dataGridView1_CellDoubleClick事件(我将在下面发布代码)上的弹出按钮单击我想使用bindingSource.Filter"时显示此弹出窗口.
我从此用户控件button_click事件尝试了此操作,但是它什么也没做,于是我以其中存在datagridview却仍然什么都没有的形式创建了一个方法.因此,我需要有关如何获取列名的帮助,而不是需要可以过滤bindingSource的make方法的帮助.
请帮我.我正在使用C#3.5 WinForms
这是用户控制按钮的代码:
Hi, I have a user control with a checkedListBox and one button. I show this fill this popup on dataGridView1_CellDoubleClick event (I''ll post code below) on popup button click I want to use bindingSource.Filter.
I tried it from this user control button_click event but it was doing nothing then I made a method in the form where there is the datagridview and still nothing. So I need help on how to get column name and than make method which can filter bindingSource.
Please help me. I am using C# 3.5 WinForms
This is the user control button code:
private void button1_Click(object sender, EventArgs e)
{
OperatorsForm of = new OperatorsForm();
var checkedvalues = checkedListBox1.CheckedItems.Cast<string>().Select(s => "'" + s + "%'").ToArray();
string d = "LoadName LIKE " + string.Join(" or ", checkedvalues);
of.filter(d);
}
这是弹出代码:
This is popup code :
private void dataGridView1_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
{
UserControl1 ucontrol = new UserControl1();
var button = sender as DataGridView;
HashSet<string> strings = new HashSet<string>();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
strings.Add(dataGridView1.Rows[i].Cells[e.ColumnIndex].Value.ToString());
}
checkedListBox1.Items.AddRange(strings.ToArray());
ucontrol.FillList(strings.ToList());
var listViewItems = strings.Select(x => new ListViewItem(x, 0)).ToArray();
ListView listView = new ListView();
listView.View = View.SmallIcon;
listView.MultiSelect = false;
listView.Items.AddRange(listViewItems);
int itemToShow = 18;
var lastItemToShow = listViewItems.Take(itemToShow).Last();
int height = lastItemToShow.Bounds.Bottom + listView.Margin.Top;
listView.Height = height;
var popup = new ToolStripDropDown();
popup.AutoSize = false;
popup.Margin = Padding.Empty;
popup.Padding = Padding.Empty;
ToolStripControlHost host = new ToolStripControlHost(ucontrol);
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
host.AutoSize = false;
host.Size = ucontrol.Size;
popup.Size = ucontrol.Size;
popup.Items.Add(host);
popup.Show(this, dataGridView1.Top, dataGridView1.Top);
}
推荐答案
我认为您的问题出在button1_Click
事件处理程序中
您的代码:
Where I think that your problem lies is in thebutton1_Click
event handler
Your Code:
private void button1_Click(object sender, EventArgs e)
{
OperatorsForm of = new OperatorsForm(); //<==== #1 =========
var checkedvalues = checkedListBox1.CheckedItems.Cast<string>().Select(s => "'" + s + "%'").ToArray();
string d = "LoadName LIKE " + string.Join(" or ", checkedvalues);
of.filter(d); //<=========== #2 =================
}
</string>
我已对问题行进行编号.
1.这将创建Form的新实例,它 not 不会获得对现有Form的引用.对其进行如下修改:
I have numbered the problem lines.
1. This creates a new instance of the Form, it does not get a reference to the existing Form. Modify it as follows:
OperatorsForm of = this.FindForm() as OperatorsForm
<罢工> 2.删除第1行之后.of
不再存在.现在要做什么取决于您是否具有filter(string filterString)
方法(a.)(b.).
一个.使用this.filter(d);
b.使用this.myBindingSource.Filter = d;
现在,您应该可以像以前一样使用of.filter(d);
.
希望我了解您的问题,对您有所帮助.
祝你好运. :)
2. After deleting line 1. of
no longer exists. What you do now depends on whether you have a filter(string filterString)
method(a.) or not (b.).
a. use this.filter(d);
b. use this.myBindingSource.Filter = d;
You should now be able to use of.filter(d);
as before.
I hope that I have understood your problem and that this helps.
Good luck. :)
这篇关于使用用户控件弹出窗口进行过滤器绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!