VB.Net question concerning the DataGridView control and filtering.

5149709249ca67ffaa6136a2432a5869
0
trosoft 101 Jan 07, 2008 at 21:05

I am using a datagridview control in my project. The user can specify up to three separate filter criteria. The program will then display these results into the datagridview in one run. My approach is to filter using the databindingsource.filter() method. The program performs the filters in an iterative fashion.

Once the first filter (based upon criteria_1) is completed, the program puts the filtered results in a separate temporary table:

table2 = myTableAdapter.GetData
myBindingSource.DataSource = table2

Next, the program automatically processes the second filter based upon criteria_2:

‘Second criteria: ComboBox.Text lists column names; TextBox.Text contains search value
myBindingSource.Filter = String.Format(CStr(cboColumnFilter2.Text) & “ = “ & CStr(txtFilterValue2.Text))

When I run the program, I receive the following exception:

EvaluateException was unhandled.
Cannot perform ‘=’ operation on System.String and System.Int32.

This error occurs when the search column is the LocationCode column.

Note: When I plug in the actual values, I have no problem (see below):

myBindingSource.Filter = String.Format(“Description Like ‘” & “Four”) & “*’ And Location = 7173”

It is just when I attempt to use the control names and properties within the filter expression that the problem occurs with the syntax:

Questions: It this the best way to process a filter based upon a series of criteria? Am I correct in the assignment of results of the first filter into table2 above? How can I fix the EvaluateException error?

0 Replies

Please log in or register to post a reply.

No replies have been made yet.