Structure into datasource


J

John

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?
 
Ad

Advertisements

M

Markus

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
 
J

John

Public Structure StructureExample
dim a as boolean
dim b as boolean
dim b as boolean
......
dim z as boolean
end structure

Dim Test as new StructureExample

I have set a datasource CheckedListBox for read an automatic names

CheckedListBox.datasource = Test.getType.Getfields

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

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck

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

End Sub

The value of structure not change, why?

Bug?
 
Ad

Advertisements

M

Markus

John,

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e
As System.Windows.Forms.ItemCheckEventArgs) Handles
CheckedListBox1.ItemCheck

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

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.Checked())

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
 

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