Solved

Previous SelectedIndex

Posted on 2004-08-25
11
278 Views
Last Modified: 2008-02-01
Hi,

I have an event set to run on SelectedIndexChange.  Is there a way to find out the last index value?  For example if the current index value is 2 and the users selects 5.  Is there a way to return that first value, 2 in this case?

I suppose I could put hidden fields on my form, but I was wondering if there was an easier way.

Ryan
0
Comment
Question by:RySk8er30
[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
  • 5
  • 5
11 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893629
nope you would need to maintain it yourself ... I would recommend subclassing the control to add the behavior though ..
0
 

Author Comment

by:RySk8er30
ID: 11893667
How would I do that?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893702
inherit from the original control and override some of the functionality.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893723
public class myComboBox : ComboBox {
      public int LastSelectedIndex {
             get ...
             set ...
      }

      I would recommend storing the value in viewstate for the control ...

}
0
 

Author Comment

by:RySk8er30
ID: 11893758
Could you be more specific.  I am new to VB.net.

Ryan
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893818
public class myDropDownList
                  inherits DropDownList

         public property LastSelectedIndex as integer
                  get
                        return m_LastSelectedIndex
                  end get
                  set(byval value as integer)
                         m_LastSelectedIndex = value
                  end get
         end property

         'override the onselectedindexchanged sub to set last selected index'

         'when the control is renderred add lastselectedindex to the viewstate.
end class

if this is just a one out though just do as you mention above and handle it in your code.
0
 

Author Comment

by:RySk8er30
ID: 11893856
How do I do these things...

'override the onselectedindexchanged sub to set last selected index'

'when the control is renderred add lastselectedindex to the viewstate.
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 25 total points
ID: 11893927
there is a method in the class named that override it public overrides sub foo() ... will make you method called instead of the other, you can add functionality this way ... remember to call mybase.method() when you do this.

ViewState["whatever"] = value ... then you can get back the value later ...

If you are not familiar with this stuff I would recommend just doing it in your page as this is much more complex (although reusable)
0
 

Author Comment

by:RySk8er30
ID: 11894053
What is the easiest way to complete my task.  I do not need to reuse anything.  Please be specific.

Ryan
0
 
LVL 7

Accepted Solution

by:
natloz earned 25 total points
ID: 11894248
This is what I do....

'Import required Namespaces
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Public Class frmMain
    Inherits System.Windows.Forms.Form

    'Global memory of selected criteria in drop downs
    Private intSelectedBranch As Integer = 0  <---------------THIS

'**********************************
'User has changed the Branch filter
'**********************************
Private Sub cboBranch_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBranch.SelectedIndexChanged
            If cboBranch.SelectedValue <> Nothing Then
                intSelectedBranch = cboBranch.SelectedValue 'Store global selection memory
            End If
End Sub

------------------
Then if you ever need to set it back eg...

If cboBranch.SelectedValue = 5 then
   cboBranch.SelectedValue = intSelectedBranch
endif
0
 

Author Comment

by:RySk8er30
ID: 11894329
Thanks guys.  I ended up just adding hidden fields to my form.

Ryan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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