Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Find, Next, and Previous buttons for a DataGrid

Status
Not open for further replies.

mohebk

MIS
Aug 23, 2005
139
US
Hi,
I am new to VB.Net. I worked with VB6 before but there are a lot of changes in VB.Net. I am trying to work with an access database through a windows form. I am using OleDbConnection and OleDbDataAdapter to connect to the database and link the table to a DataGrid. I got that part to work so far. But I am trying to create some simple navigation buttons on the form and have no idea where to start. I would like to create Find, Next, and Previous buttons to navigate through data on the DataGrid. Can you please help?

Thanks


Mo
 
By default the datagrid will contain all the rows you have retieved from the database and there will be an underlying table that you assigned as the datasource of the grid.

As a first step create the Next, Previous and Find Buttons on the form.

In the Next button's Click event handler increment the CurrentRowIndex property of the DataGrid to move the cursor foward. Don't allow this if you've reached the last record of the table.

In the Previous button's Click event handler decrement the CurrentRowIndex property of the DataGrid to move the cursor foward. Don't allow this if you've reached the first record of the table.

In the Find button's Click event handler prompt for the value and the use the Find method of the default DataView of the table to get the index of the row to be selected. Set the CurrentRowIndex to this value.

Hope this is enough to get you started.



Bob Boffin
 
Thanks Bob,
This was a lot of help. How can your reference a filed the current record on the grid to display in a lable on the form?

Thanks again.

Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top