Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sort A-Z button on vb.net form

Posted on 2013-01-14
12
Medium Priority
?
994 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.
Suggested Courses

715 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