过滤DataGridView中的元素

时间:2017-07-12 08:23:38

标签: c# datagridview

我应该只拿一些东西。 在模型标记

中获取不包含Z4TC的组

excel文件架构如下

<ConfigRegolatori>
<Id>6</Id>
<Address>92</Address>
<Category>90</Category>
<Mode>TC_K</Mode>
<Model>Z4TC</Model>
<Name>KT6</Name>
<Port>COM1</Port>
<Channel>2</Channel>
<LowerEndScale>0</LowerEndScale>
<UpperEndScale>400</UpperEndScale>
<NegativeGradient>10</NegativeGradient>
<PositiveGradient>10</PositiveGradient>
<PercX10>false</PercX10>

<ConfigRegolatori>
<Id>7</Id>
<Address>7</Address>
<Category>100</Category>
<Mode>TC_K</Mode>
<Model>M9_Servo</Model>
<Name>KT7</Name>
<Port>COM1</Port>
<Channel />
<LowerEndScale>0</LowerEndScale>
<UpperEndScale>400</UpperEndScale>
<NegativeGradient>10</NegativeGradient>
<PositiveGradient>10</PositiveGradient>
<PercX10>false</PercX10>

代码部分如下

dtConfReg = new DataTable();
                dtConfReg.ReadXml(Principale.strPathConfig + "\\ConfigRegulators.xml");
                dtConfReg.TableName = "ConfigReg";

bsouReg = new BindingSource();
                bsouReg.DataSource = dtConfReg;
                dgvwConfigReg.DataSource = bsouReg;

由于

1 个答案:

答案 0 :(得分:1)

您可以在BindingSource上设置Filter属性:

bsouReg = new BindingSource();
bsouReg.DataSource = dtConfReg;
bsouReg.Filter = "Model <> 'Z4TC'";
dgvwConfigReg.DataSource = bsouReg;

可以找到过滤器表达式的文档here