SHARE
TWEET

RawFilter_Integer_And_String_VB_NET

kilya Mar 18th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Text.RegularExpressions
  2.  
  3. Public Class Form1
  4.     Dim table As New DataTable
  5.     Dim dtable As DataTable
  6.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  7.         Dim text As String = TextBox1.Text
  8.         Dim bool As Boolean = Regex.IsMatch(text, "\d+")
  9.         If text = String.Empty Then
  10.             dtable.DefaultView.RowFilter = String.Empty
  11.         Else
  12.             If bool = True Then
  13.                 Dim id1 As Integer = Convert.ToInt32(text)
  14.                 dtable.DefaultView.RowFilter = "ID =" & id1
  15.             Else
  16.                 dtable.DefaultView.RowFilter = "Name like '%" & text & "%' OR Room like '%" & text & "%' OR Chaine like '%" & text & "%'"
  17.             End If
  18.         End If
  19.  
  20.     End Sub
  21.  
  22.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23.         table.Columns.AddRange({New DataColumn With {.ColumnName = "ID", .AutoIncrement = True, .AutoIncrementSeed = 1, .AutoIncrementStep = 1},
  24.                                 New DataColumn("Name"), New DataColumn("Room"), New DataColumn("Chaine")})
  25.  
  26.         Dim dr As DataRow = table.NewRow
  27.         dr(1) = "kilya"
  28.         dr(2) = "3"
  29.         dr(3) = "456464"
  30.         table.Rows.Add(dr)
  31.         Dim dr1 As DataRow = table.NewRow
  32.         dr1(1) = "Hand"
  33.         dr1(2) = "4"
  34.         dr1(3) = "2144546"
  35.         table.Rows.Add(dr1)
  36.  
  37.         Dim dr2 As DataRow = table.NewRow
  38.         dr2(1) = "test"
  39.         table.Rows.Add(dr2)
  40.  
  41.         Dim dr3 As DataRow = table.NewRow
  42.         dr3(1) = "dfdfd"
  43.         dr3(2) = "2"
  44.         dr3(3) = "ddfd"
  45.         table.Rows.Add(dr3)
  46.  
  47.         DataGridView1.DataSource = table
  48.         dtable = table
  49.  
  50.     End Sub
  51. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top