Click here to Skip to main content
15,888,984 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Sharing window folder Pin
helelark12319-Sep-07 3:15
helelark12319-Sep-07 3:15 
GeneralRe: Sharing window folder Pin
Dave Kreskowiak20-Sep-07 10:28
mveDave Kreskowiak20-Sep-07 10:28 
QuestionComboBox With PropertyGrid Control Pin
VB 8.018-Sep-07 18:00
VB 8.018-Sep-07 18:00 
AnswerRe: ComboBox With PropertyGrid Control Pin
Dave Kreskowiak19-Sep-07 1:56
mveDave Kreskowiak19-Sep-07 1:56 
GeneralRe: ComboBox With PropertyGrid Control Pin
VB 8.019-Sep-07 4:47
VB 8.019-Sep-07 4:47 
GeneralRe: ComboBox With PropertyGrid Control Pin
Dave Kreskowiak19-Sep-07 7:16
mveDave Kreskowiak19-Sep-07 7:16 
GeneralRe: ComboBox With PropertyGrid Control Pin
VB 8.020-Sep-07 2:42
VB 8.020-Sep-07 2:42 
GeneralRe: ComboBox With PropertyGrid Control Pin
Dave Kreskowiak20-Sep-07 9:44
mveDave Kreskowiak20-Sep-07 9:44 
OK. I see what you're getting at. The solution is pretty simple - wrap each control in a class that exposes the control and the anme of the control. Watch:
Public Class ControlData
    Private _control As Control
 
    Public ReadOnly Property Control() As Control
        Get
            Return _control
        End Get
    End Property
 
    Public ReadOnly Property Name() As String
        Get
            Return _control.Name
        End Get
    End Property
 
    Public Sub New(ByVal control As Control)
        _control = control
    End Sub
 
    Public Overrides Function ToString() As String
        Return String.Format("{0} : {1}", _control.GetType.FullName, _control.Name)
    End Function
End Class

All this does is create a wrapper for a Control that exposes the name of the control it wraps and the control itself. There's an override of the ToString method just to make the text version of this look pretty.

When you add the controls to the ComboBox, you do something like this:
Private Sub PopulateControlsCombo(ByVal parentContainer As Control)
    For Each c As Control In Panel1.Controls
        ' Create a wrapper for the control we found
        Dim d As New ControlData(c)
        ' Add the wrapped control it to the ComboBox.  The Add method automatically
        ' calls the ToString method of whatever object you pass into it.
        ComboBox1.Items.Add(d)
        ' If this control has child controls...
        If d.Control.HasChildren Then
            ' Call ourself with the current control as the new parent container.
            PopulateControlsCombo(d.Control)
        End If
    Next
End Sub

When the user selects an item in the ComboBox, the SelectedItem property will return an Object that you have to cast back to a ControlData object, then you can get at the control contained in that wrapper.
Dim d As ControlData = DirectCast(ComboBox1.SelectedItem, ControlData)
PropertyGrid1.SelectedObject = d.Control





A guide to posting questions on CodeProject[^]

Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: ComboBox With PropertyGrid Control Pin
VB 8.026-Sep-07 4:46
VB 8.026-Sep-07 4:46 
GeneralRe: ComboBox With PropertyGrid Control Pin
Dave Kreskowiak26-Sep-07 12:59
mveDave Kreskowiak26-Sep-07 12:59 
GeneralRe: ComboBox With PropertyGrid Control Pin
VB 8.026-Sep-07 21:09
VB 8.026-Sep-07 21:09 
GeneralRe: ComboBox With PropertyGrid Control Pin
VB 8.027-Sep-07 0:24
VB 8.027-Sep-07 0:24 
GeneralRe: ComboBox With PropertyGrid Control [modified] Pin
Dave Kreskowiak27-Sep-07 1:42
mveDave Kreskowiak27-Sep-07 1:42 
QuestionSystem.drawing.bitmap Pin
plural18-Sep-07 8:58
plural18-Sep-07 8:58 
AnswerRe: System.drawing.bitmap Pin
Guffa18-Sep-07 9:29
Guffa18-Sep-07 9:29 
QuestionAppleScript guy asks "Can VB.NET --------?" Pin
@largeinsd18-Sep-07 7:27
@largeinsd18-Sep-07 7:27 
AnswerRe: AppleScript guy asks "Can VB.NET --------?" Pin
Guffa18-Sep-07 9:41
Guffa18-Sep-07 9:41 
Questionaccessing mdi child Pin
Sai Yasodharan18-Sep-07 5:45
Sai Yasodharan18-Sep-07 5:45 
AnswerRe: accessing mdi child Pin
Dave Kreskowiak18-Sep-07 6:11
mveDave Kreskowiak18-Sep-07 6:11 
GeneralRe: accessing mdi child Pin
Sai Yasodharan18-Sep-07 6:28
Sai Yasodharan18-Sep-07 6:28 
QuestionIs there anyway vb.net can use to extract image feature? Pin
TeiUKei18-Sep-07 4:26
TeiUKei18-Sep-07 4:26 
AnswerRe: Is there anyway vb.net can use to extract image feature? Pin
DanB198318-Sep-07 5:50
DanB198318-Sep-07 5:50 
AnswerRe: Is there anyway vb.net can use to extract image feature? Pin
Dave Kreskowiak18-Sep-07 5:56
mveDave Kreskowiak18-Sep-07 5:56 
GeneralRe: Is there anyway vb.net can use to extract image feature? Pin
TeiUKei18-Sep-07 16:34
TeiUKei18-Sep-07 16:34 
GeneralRe: Is there anyway vb.net can use to extract image feature? Pin
Dave Kreskowiak19-Sep-07 3:42
mveDave Kreskowiak19-Sep-07 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.