简体   繁体   English

使用文本框 VB 搜索

[英]Search using textbox VB

I need to search DataGridView by date.我需要按日期搜索 DataGridView。 If I enter 2/11/2017 in text box, I want grid to show me rows that contain this date.如果我在文本框中输入2/11/2017 ,我希望网格显示包含此日期的行。 Date column in my DataGridView is named AppointmentDate and is created in SQL Server.我的 DataGridView 中的日期列名为AppointmentDate并在 SQL Server 中创建。 Type of this column is only date.此列的类型仅为日期。

I saw this, but I am using Entity Framework model, I don't know how to realize it.我看到了这个,但是我使用的是实体框架模型,我不知道如何实现它。

    dgvPacientet.CurrentCell = Nothing
    Dim found As Boolean = False
    For Each row As DataGridViewRow In dgvPacientet.Rows
        row.Visible = row.Cells("Dt_terminit").Value = txtData.Text
        If row.Visible Then found = True
    Next
    If Not found Then MsgBox("Item not found")`

Simply show or hide the rows that contain the text you want.只需显示或隐藏包含所需文本的行。

DataGridView1.CurrentCell = Nothing
Dim found as Boolean = false
For Each row As DataGridViewRow In DataGridView1.Rows
   Row.Visible = Not IsDBNull(row.Cells("DT_Terminit").Value) andalso row.Cells("DT_Terminit").Value = TextBox5.Text  
   If Row.Visible then found = true
Next
If Not found Then MsgBox("Item not found")

However you really need to parse that textbox to make sure it is a date first and if that cell contains a true Date, you need to convert the test into a date.但是,您确实需要先解析该文本框以确保它是日期,并且如果该单元格包含真正的日期,则需要将测试转换为日期。

 Dim DT As Date
 If Not Date.TryParse(TextBox5.Text, DT) Then
    MsgBox("Please enter a date") '<-- remove this line if searching on the fly... (as you enter text)
    Exit Sub
 End If

 DataGridView1.CurrentCell = Nothing

 Dim found As Boolean = False
 For Each row As DataGridViewRow In DataGridView1.Rows
    Row.Visible = Not IsDBNull(row.Cells("DT_Terminit").Value) andalso row.Cells("DT_Terminit").Value =DT
    If row.Visible Then found = True
 Next
 If Not found Then MsgBox("Item not found")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM