Structure into datasource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Structure into datasource

    Hello,

    i have this structure

    Public Structure TestStructure
    Dim a As Boolean
    Dim b As Boolean
    Dim c As Boolean
    End Structure

    Dim Test as TestStructure

    test.a = true
    test.b = false
    test.c = true

    I would want set to a datasource of a checkedlistbox and an automatic load a
    field of structure and value..

    It is possibile?





  • Markus

    #2
    Re: Structure into datasource

    I would want set to a datasource of a checkedlistbox and an automatic
    load a field of structure and value..
    >
    It is possibile?
    Databinding only works with properties, not with fields - so at least
    you have to make public properties for your fields...

    Markus

    Comment

    • John

      #3
      Re: Structure into datasource


      Public Structure StructureExampl e
      dim a as boolean
      dim b as boolean
      dim b as boolean
      ......
      dim z as boolean
      end structure

      Dim Test as new StructureExampl e

      I have set a datasource CheckedListBox for read an automatic names

      CheckedListBox. datasource = Test.getType.Ge tfields

      i read a check and uncheck of CheckedListBox and i would set a value to a
      structure

      Private Sub CheckedListBox1 _ItemCheck(ByVa l sender As Object, ByVal e As
      System.Windows. Forms.ItemCheck EventArgs) Handles CheckedListBox1 .ItemCheck

      Dim FldInf As FieldInfo
      FldInf = CheckedListBox1 .Items(e.Index)
      FldInf.SetValue (Tp, e.NewValue.Chec ked())

      End Sub

      The value of structure not change, why?

      Bug?


      Comment

      • Markus

        #4
        Re: Structure into datasource

        John,

        Private Sub CheckedListBox1 _ItemCheck(ByVa l sender As Object, ByVal e
        As System.Windows. Forms.ItemCheck EventArgs) Handles
        CheckedListBox1 .ItemCheck
        >
        Dim FldInf As FieldInfo FldInf = CheckedListBox1 .Items(e.Index)
        FldInf.SetValue (Tp, e.NewValue.Chec ked())
        >
        End Sub
        >
        The value of structure not change, why?
        >
        Bug?
        I am starting to understand your problem. Here, the problem is the
        datatype "Structure" . This is a valuetype and NOT a reference type (like
        a class would be). So, to be more specific:

        In the following line
        FldInf.SetValue (Tp, e.NewValue.Chec ked())
        you pass Tp (I think, this is your Structure object) to a method.
        Unfortunately, a copy of Tp is passed in, and this copy is modified. But
        you never get back this copy...
        So, doing it with reflection might not be the easy thing, I think you
        have to make something with "if-then-else" constructs, or - what I would
        prefere - simply make a class out of your structure. There shouldn't be
        much overhead...


        hth
        Markus

        Comment

        Working...