Windows 11
I would like to filter double values.
1. testo = text
2. numerico = numeric
3. valuta = currency
I can filter Strings
Dim srchStr As String = Me.TextBox1.text
Dim strFilter As String = "MyCol1 LIKE '*" & srchStr.Replace("'", "''") & "*'"
dv.RowFilter = strFilter
I can filter Integers
Dim srchStr As String = Me.TextBox1.Text
Dim id As Integer
If Integer.TryParse(srchStr, id) Then
dv.RowFilter = "code = " & id
Else
MessageBox.Show("Error: ........")
End If
Dim strFilter As String = "code = " & id
dv.RowFilter = strFilter
but I can not filter a double value.
I actually use this code to filter strings in my DataGridView
Private Sub MyTabDataGridView_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTabDataGridView.DoubleClick
Try
'MyRow
Dim row As Integer = MyTabDataGridView.CurrentRow.Index
'MyColumn
Dim column As Integer = MyTabDataGridView.CurrentCell.ColumnIndex
'MyColumn and MyRow
Dim ColumnRow As String = MyTabDataGridView(column, row).FormattedValue.ToString
'Header Text
Dim HeaderText As String = MyTabDataGridView.Columns(column).HeaderText
'I exclude the errors
If HeaderText = "id" Or HeaderText = "MyCol3" Or HeaderText = "MyCol4" Or HeaderText = "MyCol5" Then
Exit Sub
End If
'Ready to filter
Dim strFilter As String = HeaderText & " Like '*" & ColomnRow.Replace("'", "''") & "*'"
dv.RowFilter = strFilter
Catch ex As Exception
End Try
Any suggestion will be highly appreciated.
Solution:
Private Sub MyTabDataGridView_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTabDataGridView.DoubleClick
Try
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
'MyRow
Dim row As Integer = MyTabDataGridView.CurrentRow.Index
'MyColumn
Dim column As Integer = MyTabDataGridView.CurrentCell.ColumnIndex
'MyColumn and MyRow
Dim ColumnRow As String = MyTabDataGridView(column, row).FormattedValue.ToString
'Header Text
Dim HeaderText As String = MyTabDataGridView.Columns(column).HeaderText
'I exclude the errors
If HeaderText = "id" Then
Exit Sub
End If
If HeaderText = "MyCol1" Or HeaderText = "MyCol2" Then
'Si filtra
Dim strFilter As String = HeaderText & " Like '*" & ColumnRow & "*'"
dv.RowFilter = strFilter
ElseIf HeaderText = "MyCol3" Or HeaderText = "MyCol4" Or HeaderText = "MyCol5" Then
Dim strFilter2 As String = HeaderText & "= " & ColumnRow.Replace(",", ".")
dv.RowFilter = strFilter2
End If
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("it-IT")
'Refresh il DataGridView
Me.MyTabDataGridView.Refresh()
Catch ex As Exception
Dim lNewVariable2 As String = "mailto:[email protected]?subject=Invio Dati " & "&body= {0}{1}{2}"
System.Diagnostics.Process.Start(String.Format(lNewVariable2, ex.Message, Environment.NewLine, ex.StackTrace))
End Try
End Sub

