|
-
June 9th, 2005, 02:45 PM
#1
Drop Down List and Enabled=false
I have a form with a bunch of text boxes, and drop down list boxes. Now, there are two access states to the page, read only and full access. On read only, I turn the txt box's properties to readOnly = true, instead of enable = false, because the light gray effect with enable=false isn't really eye friendly for "read only".
Now, there is no "read only" option for drop down list boxes, and enable=false makes the text on the DDL light gray and hard to read as well, you also can't see the options.
Is there a way to make the drop down list "read only" but not allow the user to change the option, but also allow the user to be able to read the text (black text just as normal...)???
Any help please? Thanks!
-
June 9th, 2005, 03:40 PM
#2
Re: Drop Down List and Enabled=false
The way I did it on a combobox was to inherit from it, add a readonly property and in SelectedIndexChanged, if Readonly = True, set the SelectedIndex back to the OldIndex value.
-
June 9th, 2005, 04:05 PM
#3
Re: Drop Down List and Enabled=false
Ok, I know the concept of what you are doing.. Back in the school days, we created classes, then inherited the class into another, changing it a little, to make another class... But, wow, that was a while ago, and was in C++. Guess this makes yet another learning experience on my part, no problem.
Thanks for your suggestion!
-
June 9th, 2005, 04:16 PM
#4
Re: Drop Down List and Enabled=false
I didn't test this, but I think it's corrected. Add it into a class module, and compile it. Then right-click on your toolbox... select add/remove items and browse to the location of the EXE or DLL you just created. It'll add it to your toolbox.
Public Class ReadonlyListBox
Inherits System.Windows.Forms.ListBox
Private RO As Boolean = False
Private OldIndex As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Public Property [Readonly]() As Boolean
Get
Return RO
End Get
Set(ByVal Value As Boolean)
RO = Value
End Set
End Property
Public Overrides Property SelectedIndex() As Integer
Get
Return MyBase.SelectedIndex
End Get
Set(ByVal Value As Integer)
OldIndex = Value
MyBase.SelectedIndex = Value
End Set
End Property
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
If Me.Readonly Then
Me.SelectedIndex = OldIndex
Else
MyBase.OnSelectedIndexChanged(e)
End If
End Sub
End Class
-
June 10th, 2005, 07:36 AM
#5
Re: Drop Down List and Enabled=false
"On read only, I turn the txt box's properties to readOnly = true, instead of enable = false, because the light gray effect with enable=false isn't really eye friendly for "read only"."
Since you want this to happen only under "read only" condition, why can't you just do the second part of DSJ's suggestion; i.e.,
"set the SelectedIndex back to the OldIndex value"
You already know when to trigger the "read only" condition. So isn't a modified listbox overdoing it?
-
June 10th, 2005, 07:49 AM
#6
Re: Drop Down List and Enabled=false
Ok, really this is for an ASP.Net web form, backed by VB.net, so I would really like to get around the selectedIndexChanged on the server, but I guess I didn't even think about javascript being the answer, doing what you guys suggest, to bounce back to the origonal index, when the index changes, if the user's security level is not high enough..
I'll do the server side selectedIndexChanged first, only because I'm not quite sure how to pass the security variable, to the javascript function..
Also, I'm not too sure how to, or where to initialize the drop down list as the new class 'ReadonlyListBox'.. I did try and change the protected Withevents to readonlyListBox, but got a parser error on the html part of the code.
Anyhow, it looks like a great opertunity for a learning experience is ahead of me! Thanks!
-
June 10th, 2005, 08:21 AM
#7
Re: Drop Down List and Enabled=false
 Originally Posted by Gizmo001
"On read only, I turn the txt box's properties to readOnly = true, instead of enable = false, because the light gray effect with enable=false isn't really eye friendly for "read only"."
Since you want this to happen only under "read only" condition, why can't you just do the second part of DSJ's suggestion; i.e.,
"set the SelectedIndex back to the OldIndex value"
You already know when to trigger the "read only" condition. So isn't a modified listbox overdoing it?
Well, I guess the question is whether this control is used by more than 1 page. If you want to re-use, it is way better to extend it. It is not really overdoing it since it is always good to encapsulate the inner working of an object behavior.
Good Luck,
-Cool Bizs
-
June 10th, 2005, 08:28 AM
#8
Re: Drop Down List and Enabled=false
 Originally Posted by bjswift
Ok, really this is for an ASP.Net web form, backed by VB.net, so I would really like to get around the selectedIndexChanged on the server, but I guess I didn't even think about javascript being the answer, doing what you guys suggest, to bounce back to the origonal index, when the index changes, if the user's security level is not high enough..
I'll do the server side selectedIndexChanged first, only because I'm not quite sure how to pass the security variable, to the javascript function..
Also, I'm not too sure how to, or where to initialize the drop down list as the new class 'ReadonlyListBox'.. I did try and change the protected Withevents to readonlyListBox, but got a parser error on the html part of the code.
Anyhow, it looks like a great opertunity for a learning experience is ahead of me! Thanks!
Sorry, my code was for a windows form listbox!
-
June 10th, 2005, 08:30 AM
#9
Re: Drop Down List and Enabled=false
 Originally Posted by Gizmo001
[I]You already know when to trigger the "read only" condition. So isn't a modified listbox overdoing it?
Not if you've got more than one. In my case I had about 35 in one project, and it has come in handy on others as well.
-
June 10th, 2005, 10:08 AM
#10
Re: Drop Down List and Enabled=false
Ok.. I don't need to re-use the control, but I do have quite a bit of drop down lists... I'm not thinking this through properly...
How do I capture the OldIndexValue? I can only think of capturing the default of all of the drop downs, and storing them in a global, but it would be ideal to just get the origonal value when the user clicks the drop down list, using it when they finish their choice (selected index change), but the nature of selected index change doesn't work like that, leaning me towards a new class???
Well. As times goes on, an answer will come along.
-
June 10th, 2005, 10:12 AM
#11
Re: Drop Down List and Enabled=false
OK, how about this. Since it's readonly, why not use a multiline textbox instead? It would look the same.
-
June 10th, 2005, 12:19 PM
#12
Re: Drop Down List and Enabled=false
"How do I capture the OldIndexValue? I can only think of capturing the default of all of the drop downs, and storing them in a global, but it would be ideal to just get the origonal value when the user clicks the drop down list, using it when they finish their choice (selected index change), but the nature of selected index change doesn't work like that, leaning me towards a new class???"
Define a global integer for a dropdownlist box i (Dim OldIndexBoxi).
When the SelectedIndexChanged is triggered (when "not" under "read only" condition) in the SelectedIndexChanged sub, reset the old value:
oldindexboxi = dropddownlistboxi.selectedindex
When in "read only mode,"
do the reverse:
dropddownlistboxi.selectedindex = oldindexboxi
DSJ: This should work even for a large number of dropdownlistboxes by using array of integers for oldindexes and declariing the dropdownlistboxes as arrays and matching the two indices.
-
June 10th, 2005, 12:47 PM
#13
Re: Drop Down List and Enabled=false
Questions:
1. Is this an ASP.NET app?
2. Who set the default value for the dropdownlist?
Good Luck,
-Cool Bizs
-
June 10th, 2005, 12:50 PM
#14
Re: Drop Down List and Enabled=false
My suggestion was for Windows not ASP app.
-
June 10th, 2005, 12:54 PM
#15
Re: Drop Down List and Enabled=false
 Originally Posted by Gizmo001
[I]
DSJ: This should work even for a large number of dropdownlistboxes by using array of integers for oldindexes and declariing the dropdownlistboxes as arrays and matching the two indices.
My OOP solution works just fine, thanks... no need for arrays or any matching logic. I prefer KISS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|