Link to home
Start Free TrialLog in
Avatar of zipnotic
zipnoticFlag for United States of America

asked on

Sort A-Z button on vb.net form

Hello,

How would I add a sort button to my tool bar that works like the ones on an MS Access form?
I have the data in a dataset from an MS Access database and I would like the user to be able to click in one of the text boxes (or combo boxes) then click the sort button and order the records on the form by the box they had just clicked in?


vs 2010
ms access
vb.net
Thanks!
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

How are you displaying your data? If you have it in a DataGridView (or DataGrid), the user can simply click on the column header to sort the data according to that column (unless you've specifically disabled that). Does that meet your needs? If not, please clarify your display method, and why you don't want to use the column header functionality.
Avatar of zipnotic

ASKER

I am not using the datagridview.  I have data displayed on a details form.  I want the user to be able to click in one of the boxes to set the focus there and then click on the sort a-z or z-a button and have the records re ordered by that field.  I have used only the built in (VS 2010) dataset tools to link to an MS Access db for this application otherwise I would probly build the SQL dynamically to reload the form data.  I also want to create a search box that searches for matches based on whichever text/combo is selected (ala the filter by selection in MS Access), but I suppose that is another question.
I'm sorry, but I'm not clear. What do you mean by "displayed on a details form"? Is this application created in Visual Studio/VB 2010, or are you running Access and using Visual Basic for Applications? If it's VS 2010, what type of control(s) are you using to display the data?
This is a front end written with Visual Studio 2010 and vb.net.  The controls are a series of text boxes, datetime pickers, checkboxes, and comboboxes.  I am using the built in functionality of the datasource constructor within VS 2010 to connect to an MS Access backend.  Each field from the dataset is bound to one of the controls on the form.  I use the bindingsource control to navigate through the records one at a time, not in a datagridview.  I'd like to provide an easier way to find records with the sort feature.
Any Ideas?  This seems like it should be a straightforward process.  I tried to sort the dataset and refresh the form but that doesn't work.

        Me.DataSet.Tables("Criteria").DefaultView.Sort = "Address asc"

        Me.Refresh()
So you're only displaying a single record at a time? The goal then would be to choose a particular field and the next time the user moves forward or backward one record, it will display the next/previous record according to that field.

Are you using a ToolStrip as the container for your toolbar? It seems like what you really want is to know the control that has focus just before you click on the sort button. Unfortunately, I don't know a way to do that, aside from the really tedious method of setting a variable (with the control's name) in the Enter event handler for each control, then reading that variable to decide which database field to sort on.

Refresh isn't going to do anything, in the example code you posted, because the sort doesn't change which record is being displayed. Changing the sort for the view won't repopulate the form; it would just in theory change the next record to display, assuming that your BindingSource is using the DefaultView of the table to retrieve the records.
What I'd like to create is what MS Access has built in.  This front end is a rewrite from an access front end.  In Access you can click the sort buttons and the form will reorder itself based on which field you had selected.  I also wanted to create a 'datasheet' view button that allows you to look at the records in a datasheet and flip over to the 'form view' - just like access.  I was hoping this would be easier in .Net than it appears.  The end users want to get away from Access, but it's so easy to create funcitonality vs. .Net/ VS2010.

-My navigator is on it's own docked to the bottom of the form.  I couldn't think of a good reason to embed it in a tool bar.
ASKER CERTIFIED SOLUTION
Avatar of zipnotic
zipnotic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm sorry I couldn't be of assistance. It seems like this is one situation where, to my knowledge, Access's UI can do something that VB can't...
No guidance provided.