Solved

Sort A-Z button on vb.net form

Posted on 2013-01-14
12
950 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

910 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

25 Experts available now in Live!

Get 1:1 Help Now