• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Previous SelectedIndex

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
RySk8er30
Asked:
RySk8er30
  • 5
  • 5
2 Solutions
 
gregoryyoungCommented:
nope you would need to maintain it yourself ... I would recommend subclassing the control to add the behavior though ..
0
 
RySk8er30Author Commented:
How would I do that?
0
 
gregoryyoungCommented:
inherit from the original control and override some of the functionality.
0
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.

 
gregoryyoungCommented:
public class myComboBox : ComboBox {
      public int LastSelectedIndex {
             get ...
             set ...
      }

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

}
0
 
RySk8er30Author Commented:
Could you be more specific.  I am new to VB.net.

Ryan
0
 
gregoryyoungCommented:
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
 
RySk8er30Author Commented:
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
 
gregoryyoungCommented:
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
 
RySk8er30Author Commented:
What is the easiest way to complete my task.  I do not need to reuse anything.  Please be specific.

Ryan
0
 
natlozCommented:
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
 
RySk8er30Author Commented:
Thanks guys.  I ended up just adding hidden fields to my form.

Ryan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now