?
Solved

CallByName on passed Objects

Posted on 2007-07-26
2
Medium Priority
?
279 Views
Last Modified: 2008-01-09
Hello,

I am trying to write a helper routine for creating column objects and I don't seem to be able to make it work.

Here is the code:

      ' --- COL 1 ---

      Dim Props As New Hashtable

      Props("Name") = "Checked" & "uiMasterList" & "CheckBoxColumn"
      Props("DataPropertyName") = "Checked"
      Props("HeaderText ") = "Checked"
      Props("AutoSizeMode ") = DataGridViewAutoSizeColumnMode.AllCells
      Props("SortMode ") = DataGridViewColumnSortMode.Automatic
      Props("Frozen ") = True
      Props("ValueType ") = System.Type.GetType("System.Int32")
      Props("FalseValue ") = 0
      Props("TrueValue ") = 1

      Dim ColCheckBox As New DataGridViewCheckBoxColumn

      ColCheckBox = CType(DataGridViewCreateColumn(DataGridViewColumnTypes.CheckBoxColumn, Props), System.Windows.Forms.DataGridViewCheckBoxColumn)

      uiMasterList.Columns.Add(ColCheckBox)


Module UiHelpers

      Public Enum DataGridViewColumnTypes
            ButtonColumn = 1
            CheckBoxColumn
            ComboBoxColumn
            ImageColumn
            LinkColumn
            TextBoxColumn
      End Enum

      Function DataGridViewCreateColumn( _
       ByVal ColumnType As DataGridViewColumnTypes, _
       Optional ByVal ColumnProperties As Hashtable = Nothing) As DataGridViewColumn

    Dim ExcludeProperties As New Hashtable

    ' Duplication in code in the case statement is for the complier - need to find another way another time.
    Select Case ColumnType

      Case DataGridViewColumnTypes.ButtonColumn
        Dim Column As New DataGridViewButtonColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

      Case DataGridViewColumnTypes.CheckBoxColumn
        Dim Column As New DataGridViewCheckBoxColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

      Case DataGridViewColumnTypes.ComboBoxColumn
        Dim Column As New DataGridViewComboBoxColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

      Case DataGridViewColumnTypes.ImageColumn
        Dim Column As New DataGridViewImageColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

      Case DataGridViewColumnTypes.LinkColumn
        Dim Column As New DataGridViewLinkColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

      Case DataGridViewColumnTypes.TextBoxColumn
        Dim Column As New DataGridViewTextBoxColumn
        AssignObjectValues(Column, ColumnProperties, ExcludeProperties)
        Return Column

    End Select

    Return New DataGridViewColumn 'Just for the complier, never executed

  End Function

  Sub AssignObjectValues( _
   ByVal Obj As Object, _
   Optional ByVal Properties As Hashtable = Nothing, _
   Optional ByVal ExcludeProperties As Hashtable = Nothing)

    If Not IsNothing(Properties) Then
      Dim Prop As DictionaryEntry
      If IsNothing(ExcludeProperties) Then ExcludeProperties = New Hashtable
      For Each Prop In Properties
        If ExcludeProperties.ContainsKey(Prop.Key.ToString) = False Then
          Try
            Console.WriteLine("P: " & Prop.Key.ToString)
            CallByName(Obj, Prop.Key.ToString, CallType.Set, Prop.Value) ' <-- PROBLEM HERE
          Catch ex As Exception
            WriteErrorToConsole(ex)
          End Try
        End If
      Next
    End If
  End Sub

End Module

AND IT GIVES ME THESE ERRORS:

P: AutoSizeMode
Level: 0
Message: Public member 'AutoSizeMode ' on type 'DataGridViewCheckBoxColumn' not found.
P: Name
P: HeaderText
Level: 0
Message: Public member 'HeaderText ' on type 'DataGridViewCheckBoxColumn' not found.
P: Frozen
Level: 0
Message: Public member 'Frozen ' on type 'DataGridViewCheckBoxColumn' not found.
P: DataPropertyName
P: FalseValue
Level: 0
Message: Public member 'FalseValue ' on type 'DataGridViewCheckBoxColumn' not found.
P: TrueValue
Level: 0
Message: Public member 'TrueValue ' on type 'DataGridViewCheckBoxColumn' not found.
P: SortMode
Level: 0
Message: Public member 'SortMode ' on type 'DataGridViewCheckBoxColumn' not found.
P: ValueType
Level: 0
Message: Public member 'ValueType ' on type 'DataGridViewCheckBoxColumn' not found.

Any help much appreciated.
0
Comment
Question by:RegProctor
2 Comments
 
LVL 8

Accepted Solution

by:
theplonk earned 2000 total points
ID: 19580198
Get rid of the trail spaces on property names. E.g. When defining the properties in your hashtable there is a space at the end of the key name 'AutoSizeMode '

See how that goes.
0
 
LVL 1

Author Comment

by:RegProctor
ID: 19580805
I can't believe I missed that. I've moving into the realm of handling more of the business end of my business and my programming seems to be suffering somewhat as a result. I guess it's a good thing that stuff is happening but it's annoying to miss something like that.

Anyway, thanks a whole bunch.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question