Derived Combobox with Locked/Readonly Property working until Databind

A

aaapaul

I have a derived combobox with locking property. The user can see,
what items are in the combobox but he can' t change them.

This is my code:
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class LCombo
Inherits ComboBox

Private m_blnLocked As Boolean
Private m_oldIndex As Integer

Public Property Locked() As Boolean
Get
Return Me.m_blnLocked
End Get
Set(ByVal value As Boolean)
m_blnlocked = value
End Set
End Property

Public Overrides Property SelectedIndex() As Integer
Get
Return MyBase.SelectedIndex
End Get
Set(ByVal Value As Integer)
m_oldIndex = Value
MyBase.SelectedIndex = Value 'Line XYZ
End Set
End Property

Sub New()
MyBase.New()
End Sub


Private Sub LCombo_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Me.SelectedIndexChanged
If Me.m_blnLocked Then
Me.SelectedIndex = m_oldIndex
End If

End Sub

Starting my program, I get an error at Line XYZ (see above).
"InvalidArgument=Value with Value 0 is for SelectedIndex invalid
Parametername: SelectedIndex

Do you have any idea? Is this possible at all?

Thanks
aaaPaul
 
B

Brendon Bezuidenhout

aaapaul,

When a ComboBox is populated the selected index changes each time - so when
your form initially opens there is no data binding. Then the binding starts
(I'm assuming this is how you are doing it) - What you COULD do is add a
Boolean class level field "m_init" or something else and set it to True when
your new method is called - Out of curiosity how is the ComboBox populated?

<code>
Sub New()
m_init = True
MyBase.New()
End Sub
</code>

HTH
Brendon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top