OOP Module8 HFEstrada Oct22 New
OOP Module8 HFEstrada Oct22 New
Declaration:
This learning module is an exclusive property of Dr. Yanga’s Colleges, Inc., as an essential part of the
REIMAGINED Learning Program for the Academic Year 2020-2021, and shall only be used by and for
DYCIans. No part of this learning module shall be reproduced, distributed, transmitted, and/or sold, without
the consent of DYCI.
MODULE 8
SEARCH AND FILTER RECORD
This module will help you acquire knowledge on how to search single record and fil-
ter record loaded in a data grid view using VB.net and MySQL
Creating Database:
Create a database named `vbmysqldb`. Execute the following query to create a table.
2
Execute the following query to add the data in the table that you have created.
INSERT INTO `tbluseraccounts` (`ID`, `fullname`, `username`, `pass`)
VALUES (1, 'liza', 'liza', 'liza'),
(2, 'juan', 'juan', 'juan'),
(3, 'honey', 'honey', 'honey');
Creating Application
Step 1 :Open Microsoft Visual Studio and create a new windows form application in
visual basic. Change the project name and the location if necessary.
3
Step 2 : Design the form just like shown below.
Step 4
Create a connection between Visual Basic and MySQL Database. After that, declare all
the classes that are needed.
4
Step 5. On form load call the ConnectDatabase() function to establish connection
5
Step 6: Add functionality to your Back Button
6
Step 8: Add a function to filter record by ID: ToString used to convert DBNull into
string vlaue
7
Step 10: Add a function to filter record by Username
8
Step 11: Add functionality to your Clear button and Keypress event to your TXTDATA
9
Search/Filter datagridview using textbox.
Step 1: Add new windows form and design as shown below:
Step2. After setting up the Form, double click it and do this code for setting up the
connection of MySQL Database to Visual Basic and declare all the classes that are
needed.
10
Step 3: Write the function to connect to your database
11
Step 5: Add the key press event of your TXTDATA
12
VB.NET DataGridView
The DataGridView control provides a customizable table for displaying data.
This control is designed to be a complete solution for displaying tabular data with
Windows Forms.
Also the DataGridView class allows us to customization of cells, rows, columns, and
borders through the use of its properties
Lightning bolt.
When using the DataGridView control in Windows Forms, you should use
the lightning bolt panel. This allows you to manipulate the events on the
control. DataGridView has many events, and this article doesn't describe
them all.
DataGridView.AutoResizeColumns Method
Adjusts the width of all columns to fit the contents of their cells.
Adjusts the width of all columns to fit the contents of all their cells, including the
header cells.
OVERLOADS
AutoResizeColumns()
Adjusts the width of all columns to fit the contents of all their cells, including the
header cells.
AutoResizeColumns(DataGridViewAutoSizeColumnsMode)
Adjusts the width of all columns using the specified size mode.
AutoResizeColumns(DataGridViewAutoSizeColumnsMode, Boolean)
Adjusts the width of all columns using the specified size mode, optionally calculating
the widths with the expectation that row heights will subsequently be adjusted.
13
DataGridView.AllowUserToResizeColumns Property
Gets or sets a value indicating whether users can resize columns.
DataGridView.AllowUserToDeleteRows Property
Gets or sets a value indicating whether the user is allowed to delete rows from
the DataGridView.
DataGridView.AllowUserToAddRows Property
Gets or sets a value indicating whether the option to add rows is displayed to the user.
DataGridView.AllowUserToResizeRows Property
Gets or sets a value indicating whether users can resize rows.
DataGridView.DefaultCellStyle Property
Gets or sets the default cell style to be applied to the cells in the DataGridView if no
other cell style properties are set.
DataGridView.RowsDefaultCellStyle Property
Gets or sets the default style applied to the row cells of the DataGridView.
DataGridView.AlternatingRowsDefaultCellStyle Property
Gets or sets the default cell style applied to odd-numbered rows of the DataGridView.
DataGridView.BackColor Property
Gets or sets the background color for the control.
14
Name: _____________________________________________ Rating: ________________
Year and Section:_____________ Professor / Instructor: __________________________
Due of Submission: _____________________________
4. Add a functionality to filter the data in the DataGridView when your enter ei-
ther the ID, name or username of the user.
15
Name: _____________________________________________ Rating: ________________
Year and Section:_____________ Professor / Instructor: __________________________
Due of Submission: _____________________________
7. Add functionality to the search button and txtData “Keypress Event” accord-
ing to the value of your “cbooption” and load the retrieved record in a text-
field in the group box.
16
guru99.com. (2020, June 6). V B.NET Tutorial: Learn V B.Net programming. Retrieved
from https://www.guru99.com/vb-net-tutorial.html.
hscripts.com. (2020). V B.Net Tutorial - Microsoft Visual Basic Programming. Re-
trieved from https://www.hscripts.com/tutorials/vbnet/index.php.
Pepito, C. P. (2011). Itnroduction to V isual Basic 2008 Programming. Philippines: Na-
tional Book Store.
Tamayo, J. D., Taguinod, I. C., Gibaga, G. R., Malang, B. P., Macatangga, R. S., &
Casuco Jr., F. S. (2014). V B.Net Programming. Malabon City: Jimczyville Pub-
lications.
techotopia.com. (2020). V isual Basic Essentials. Retrieved from techotopia.com/
index.php/Visual_Basic_Essentials
tutorialspoint.com. (2020, June 6). V B.Net Programming Tutorial. Retrieved from
https://www.tutorialspoint.com/vb.net/index.htm.
vb.net-informations.com. (2020, June 6). V B.NET Tutorial. Retrieved from http://
vb.net-informations.com/.
vbtutor.net. (2020, June 6). V isual Basic 2008 Tutorial. Retrieved from https://
www.vbtutor.net/vb2008/vb2008tutor.html.
17