fede186
fede186

Reputation: 89

Filter elements in a DataGridView

I should only take some items. Take groups that do not contain Z4TC in the Model tag

The excel file schema is as follows

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

The code part is the following

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

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

Thanks

Upvotes: 2

Views: 51

Answers (1)

Markus
Markus

Reputation: 22456

You can set the Filter property on the BindingSource:

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

The documentation for the filter expression can be found here.

Upvotes: 1

Related Questions