Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting READONLY property in control collection (How) 1

Status
Not open for further replies.

Kieran777

Programmer
Apr 23, 2003
26
0
0
AU
'I can iterate through controls on my form and set the .text and .enable property (see below). However, when I try to set the .READONLY property I get an error. How can this be done.

'Code
Dim i As Integer
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).GetType() Is GetType(System.Windows.Forms.TextBox) Then
Me.Controls(i).Text = ""
Me.Controls(i).Enabled = True
Me.Controls(i).ForeColor = color.blue
Me.Controls(i).BackColor = color.yellow
' ...I want to set the READONLY property like
Me.Controls(i).READONLY = False
'but this doesn't work
End If

Any Help appreciated.

Cheers
Kieran
 
You need to set the type of the control to a text box using

Ctype(Me.controls(i), System.Windows.Forms.TextBox).readonly = True
 
*** Top Stuff ***
That really helped - Thanks for your help.
My working code now looks like:

Dim t As TabControl = CType(Me.TabControl1.TabPages(0).Controls(i), System.Windows.Forms.TabControl)
Dim p As TabPage
Dim tb As TextBox
Dim o As Integer
For Each p In t.TabPages
For Each c In p.Controls
If c.GetType Is GetType System.Windows.Forms.TextBox) Then
CType(c, System.Windows.Forms.TextBox).ReadOnly = False
CType(c, System.Windows.Forms.TextBox).Text = ""
CType(c, System.Windows.Forms.TextBox).Enabled = True
CType(c, System.Windows.Forms.TextBox).ForeColor = m_Colour_PrefEditFG
CType(c, System.Windows.Forms.TextBox).BackColor = m_Colour_PrefEditBG
ElseIf c.GetType Is GetType(CustomControls.TextBoxEx) Then
CType(c, CustomControls.TextBoxEx).ReadOnly = False
CType(c, CustomControls.TextBoxEx).Text = ""
CType(c, CustomControls.TextBoxEx).Enabled = True
CType(c, CustomControls.TextBoxEx).ForeColor = m_Colour_PrefEditFG
CType(c, CustomControls.TextBoxEx).BackColor = m_Colour_PrefEditBG
ElseIf c.GetType Is GetType(System.Windows.Forms.ComboBox) Then

etc.......................
Endif

Thank You Again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top