Share vb.net search in datagridview,

#vb.net #Datagridview #search ## Cách tìm kiếm trong DataGridView trong VB.NET

## Cách tìm kiếm trong DataGridView trong vb.net

Trong hướng dẫn này, bạn sẽ tìm hiểu cách tìm kiếm trong DataGridView trong VB.NET.Chúng tôi sẽ sử dụng phương thức `find` của điều khiển` datagridview`.

### 1. Tạo một dự án mới

Để bắt đầu, hãy tạo một dự án mới trong Visual Studio.Đối với hướng dẫn này, chúng tôi sẽ sử dụng ứng dụng Windows Forms.

### 2. Thêm DataGridView vào biểu mẫu của bạn

Tiếp theo, thêm một datagridview vào biểu mẫu của bạn.Bạn có thể làm điều này bằng cách nhấp chuột phải vào biểu mẫu và chọn ** Thêm> DataGridView **.

### 3. Liên kết DataGridView với nguồn dữ liệu

Bây giờ, chúng ta cần liên kết DataGridView với nguồn dữ liệu.Đối với hướng dẫn này, chúng tôi sẽ sử dụng một dữ liệu.

Để thực hiện việc này, nhấp chuột phải vào DataGridView và chọn ** BindingSource **.Trong hộp thoại ** BindingSource **, nhấp vào ** Thêm ** và chọn DataTable mà bạn muốn liên kết với DataGridView.

### 4. Thêm hộp tìm kiếm vào biểu mẫu của bạn

Tiếp theo, chúng tôi cần thêm một hộp tìm kiếm vào biểu mẫu của bạn.Bạn có thể làm điều này bằng cách nhấp chuột phải vào biểu mẫu và chọn ** Thêm> TextBox **.

### 5. Thêm phương thức `find` vào mã của bạn

Bây giờ, chúng tôi cần thêm phương thức `find` vào mã của bạn.Phương thức `find` có hai tham số: văn bản tìm kiếm và các tùy chọn tìm kiếm.

Các tùy chọn tìm kiếm hơi phức tạp, nhưng đối với hướng dẫn này, chúng tôi sẽ chỉ sử dụng các giá trị mặc định.

Để thêm phương thức `find` vào mã của bạn, nhấp đúp vào hộp tìm kiếm và thêm mã sau:

`` `VBNet
Private Sub txtSearch_TextChanged (người gửi là đối tượng, e như EventArgs) xử lý txtSearch.TextChanged
dgvproducts.find (txtsearch.text)
Kết thúc phụ
`` `

### 6. Chạy ứng dụng của bạn

Bây giờ, hãy chạy ứng dụng của bạn và thử tìm kiếm một sản phẩm.Bạn sẽ thấy kết quả tìm kiếm của bạn được hiển thị trong DataGridView.

### Phần kết luận

Trong hướng dẫn này, bạn đã học cách tìm kiếm trong DataGridView trong VB.NET.Bạn có thể sử dụng kỹ thuật này để tìm kiếm dữ liệu trong bất kỳ DataGridView mà bạn tạo.

##### 5 hashtags

* #vb.net
* #Datagridview
* #tìm kiếm
* #tutorial
* #Programming
=======================================
#vb.net #Datagridview #search ##How to search in a datagridview in VB.NET

##How to search in a datagridview in VB.NET

In this tutorial, you will learn how to search in a datagridview in VB.NET. We will use the `Find` method of the `DataGridView` control.

### 1. Create a new project

To get started, create a new project in Visual Studio. For this tutorial, we will use a Windows Forms application.

### 2. Add a datagridview to your form

Next, add a datagridview to your form. You can do this by right-clicking on the form and selecting **Add > DataGridView**.

### 3. Bind the datagridview to a data source

Now, we need to bind the datagridview to a data source. For this tutorial, we will use a DataTable.

To do this, right-click on the datagridview and select **BindingSource**. In the **BindingSource** dialog box, click **Add** and select the DataTable that you want to bind to the datagridview.

### 4. Add a search box to your form

Next, we need to add a search box to your form. You can do this by right-clicking on the form and selecting **Add > TextBox**.

### 5. Add the `Find` method to your code

Now, we need to add the `Find` method to your code. The `Find` method takes two parameters: the search text and the search options.

The search options are a bit complex, but for this tutorial, we will just use the default values.

To add the `Find` method to your code, double-click on the search box and add the following code:

```vbnet
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
dgvProducts.Find(txtSearch.Text)
End Sub
```

### 6. Run your application

Now, run your application and try searching for a product. You should see the results of your search displayed in the datagridview.

### Conclusion

In this tutorial, you learned how to search in a datagridview in VB.NET. You can use this technique to search for data in any datagridview that you create.

###### 5 Hashtags

* #vb.net
* #Datagridview
* #search
* #tutorial
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top