Solved

Sort A-Z button on vb.net form

Posted on 2013-01-14
12
945 Views
Last Modified: 2013-11-28
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!
0
Comment
Question by:zipnotic
  • 6
  • 4
12 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 38790386
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.
0
 

Author Comment

by:zipnotic
ID: 38796846
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.
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 38797655
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?
0
 

Author Comment

by:zipnotic
ID: 38798820
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.
0
 

Author Comment

by:zipnotic
ID: 38802842
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()
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 20

Expert Comment

by:ElrondCT
ID: 38803309
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.
0
 

Author Comment

by:zipnotic
ID: 38803348
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.
0
 

Accepted Solution

by:
zipnotic earned 0 total points
ID: 38862258
Oh well...
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 38862585
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...
0
 

Author Closing Comment

by:zipnotic
ID: 38875502
No guidance provided.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now