Solved

Sort A-Z button on vb.net form

Posted on 2013-01-14
12
962 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
set focus to tabbed sub form 10 39
90 days before current date 12 31
Copying an open file 3 20
vb.net convert long time to mm:ss 23 12
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

856 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