选型页筛选功能:DockWindow3 顶栏新控件 comboBox1(关键字,可输入带历史)+button1(筛选/清除切换)——对汇总表 元件名称/规格/图纸规格 三列 RowFilter 模糊筛选,回车触发,空关键字清除;不动数据源,刷新加载自动重置
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using WeifenLuo.WinFormsUI.Docking;
|
||||
|
||||
namespace 成套报价软件
|
||||
@@ -12,6 +12,53 @@ namespace 成套报价软件
|
||||
this.BackColor = System.Drawing.Color.White;
|
||||
Text = "选型";
|
||||
TabText = "选型";
|
||||
|
||||
// ★ 筛选(2026-10-02):comboBox1 输入关键字,button1 对汇总表(advancedDataGridView1)
|
||||
// 的 元件名称/规格/图纸规格 三列做模糊筛选;关键字为空时点击=清除筛选
|
||||
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; // 可手动输入
|
||||
button1.Click += button1_筛选_Click;
|
||||
comboBox1.KeyDown += (s, e) =>
|
||||
{
|
||||
if (e.KeyCode == System.Windows.Forms.Keys.Enter)
|
||||
{
|
||||
button1_筛选_Click(s, e);
|
||||
e.SuppressKeyPress = true; // 防回车 beep
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>筛选/清除:对汇总表(advancedDataGridView1)的 元件名称/规格/图纸规格
|
||||
/// 三列任一包含关键字即显示(RowFilter 过滤视图,不动数据源,刷新加载自动重置)。</summary>
|
||||
private void button1_筛选_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dt = advancedDataGridView1.DataSource as System.Data.DataTable;
|
||||
if (dt == null) return; // 尚未加载数据
|
||||
string kw = (comboBox1.Text ?? "").Trim();
|
||||
if (kw.Length == 0)
|
||||
{
|
||||
dt.DefaultView.RowFilter = "";
|
||||
button1.Text = "筛选";
|
||||
return;
|
||||
}
|
||||
// RowFilter LIKE 通配符/引号转义
|
||||
string esc = kw.Replace("'", "''").Replace("[", "[[]").Replace("%", "[%]").Replace("*", "[*]");
|
||||
string like = " LIKE '%" + esc + "%'";
|
||||
dt.DefaultView.RowFilter = "元件名称" + like + " OR 规格" + like + " OR 图纸规格" + like;
|
||||
button1.Text = "清除";
|
||||
|
||||
// 关键字入下拉历史(去重置顶,最多 20 条)
|
||||
int idx = comboBox1.Items.IndexOf(kw);
|
||||
if (idx >= 0) comboBox1.Items.RemoveAt(idx);
|
||||
comboBox1.Items.Insert(0, kw);
|
||||
while (comboBox1.Items.Count > 20) comboBox1.Items.RemoveAt(comboBox1.Items.Count - 1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(this, "筛选失败:" + ex.Message, "选型",
|
||||
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user