I need bind a Datagrid with Collection, but Whe I bind DatagridA.DataSource=v.Detalle. In the DataGrid doesn't view nothing. To resolv this problem i am doing the following.
dim a as ArrayList= new ArrayList
dim aux as DetallePedidoVenta
for each d in v.Detalle
aux.add(d)
end foreach
DataGridA.DataSource=aux
This is correct, because the datagrid support ArrayList, but the CPersistentCollection noooo????
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dim a As IList = obj.DetallePedidoVenta
Me.DataGridItems.DataSource = a
Where DetallePedidoVenta is a CPersistentCollection.
but, it isn't view in the DataGrid.
I thing that CPersistenCollection must have a method that an arrayList returns with all the articles of the collection. This is very importantly to connect to the DataGrids and to allow to order the Grid.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Binding to an IList should work, but you may need to set a specific mapping name. I'm no expert on complex binding and if you look at the documentation for the datagrid with the ArrayList you have to set a specific mapping name for it to work.
If you must use an interface try using the IBindingList like this:
dim a as IBindingList = obj.DetallePedidoVenta
Me.DataGridItems.DataSource = a
where AuthUser.Credenciais.Grupos is a CPersistentCollection.
I'm tring to bind the Nome and GUI properties of Grupo's of the Usuario class to a dropdown lista, but i just can bind properties of the MebrosGrupo class.
Can i indirect bind it throug Grupo.Nome and Grupo.GID or should i procede any other way?
Thanks,
Claudio
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Usario.Grupos is a reference to a MembroGroupo class not a Grupo class.
This means the collection will contain MembroGrupo objects not Grupo objects.
I haven't tried the indirect binding and I'm not 100% sure of how the internals in databinding work but I'm pretty sure that binding works using first level property names only and does no parsing of the object name to handle nesting. I could be wrong so I would suggest that you try it first - or check on google, msdn, etc.
In any case, given the class map supplied I am assuming that you are actually wanting a Many-to-Many association between Usario and Grupo and that MembroGrupo is used only for managing the association.
If this is the case then I would suggest that you add a new collection to the Usario object for holding Grupo objects. As items get added and removed from the MembroGrupo collection (use events) simply add/remove the linked Grupo object from the new colelction. Then do databinding on the new Grupo collection instead of the MembroGrupo collection.
I would also recommend strongly typing the collections as it really helps with the databinding process when you want to use data grids, etc.
Let me know how if it works for you.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
in fact, it's a OnetoMany association between the Usuario and Grupo classes. An Usuario (User) belongs to N Grupos (Groups). But i've changed the approach. I've included a propertie call Nome in the MembroGrupo class and there i load the Nome propertie of Grupo class at runtime.
But i've got some other questions.
There some simple task i wish to do but i'm not certain the way i should.
I 've seen how much development time we can gain using the Framework, but i figuring out some way to gain some more! :-p
Can you give some directions in:
1) Sorting CPersistentCollection.
Well, i wrote the class do return the MembroGrupo class, but when i bind it to a dropdown list, it comes out of order. Is there any quick way to do the sorting at the Collection?!
2) Search inside a Collection or Class;
When i create a Usuario Object, i often need to search within the MembroGrupo collection. Can i filter only the returned collection?
Well, i think it covers the most usual operations, that i didn't find any example in the FAQ or Nunits tests (or i think so).
Thanks for you help,
Claudio
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's no supprot for sorted collections at this stage. The objects in the collection are ordered based on the way they are added.
Obviously you can subclass the CPersistentCollection yourself and add sorting, but you'll need to watch out for what happens when you have objects with multiple key fields, and how those fields should be ordered.
2) Searching in a collection
Once again, I haven't done anything in this regard. Assuming you only sort on key fields, searching efficiently depends on having a sorted collection.
Searching inefficiently is just a "for each" loop.
By the way, I think both ideas are good ideas. If you don't want to do the code yourself, just submit a tracker item for each in the feature requests. And if you do write the code, I'd love to see it.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a problem or not???
I need bind a Datagrid with Collection, but Whe I bind DatagridA.DataSource=v.Detalle. In the DataGrid doesn't view nothing. To resolv this problem i am doing the following.
dim a as ArrayList= new ArrayList
dim aux as DetallePedidoVenta
for each d in v.Detalle
aux.add(d)
end foreach
DataGridA.DataSource=aux
This is correct, because the datagrid support ArrayList, but the CPersistentCollection noooo????
It should work straight away since it implements IList and IBindable...
I'm trying to remember off the top of my head, but for the datagrid to work properly you need to strongly type the collection (ie create a subclass).
If you want editable, you need to override the relevant methods of the IEditableObject interface from CPersistentObject as well.
There should be a sample project in the download that does data binding to a datagrid using these methods that you can follow.
I am trying this:
Dim a As IList = obj.DetallePedidoVenta
Me.DataGridItems.DataSource = a
Where DetallePedidoVenta is a CPersistentCollection.
but, it isn't view in the DataGrid.
I thing that CPersistenCollection must have a method that an arrayList returns with all the articles of the collection. This is very importantly to connect to the DataGrids and to allow to order the Grid.
Binding to an IList should work, but you may need to set a specific mapping name. I'm no expert on complex binding and if you look at the documentation for the datagrid with the ArrayList you have to set a specific mapping name for it to work.
If you must use an interface try using the IBindingList like this:
dim a as IBindingList = obj.DetallePedidoVenta
Me.DataGridItems.DataSource = a
otherwise try to use the object itself
Me.DataGridItems.DataSource = obj.DetallePedidoVenta
Let me know how you go.
- Richard.
Hi Richard,
i've got the following mapping:
<?xml version="1.0" encoding="utf-8" ?>
<map>
<database name="DXMDB" class="CMsAccessDatabase">
<parameter name="name" value="c:\inetpub\wwwroot\dxm.site\data\dxm.mdb" />
<parameter name="user" value="anyuser" />
<parameter name="password" value="anypassword" />
</database>
<class name="Usuario" table="usuario" database="DXMDB">
<attribute name="UID" column="usuario_id" identity="true" key="primary"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
<attribute name="Nome" column="usuario_nm"/>
<attribute name="Email" column="usuario_email" find="true"/>
<attribute name="Senha" column="usuario_senha" find="true"/>
<attribute name="Adm" column="administrador"/>
<attribute name="Grupos"/>
</class>
<class name="MembroGrupo" table="usuario_grupo" database="DXMDB">
<attribute name="UGID" column="ugid" identity="true" key="primary"/>
<attribute name="GID" column="grupo_id"/>
<attribute name="UserID" column="usuario_id"/>
<attribute name="Grupo"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
</class>
<class name="Grupo" table="grupo" database="DXMDB">
<attribute name="GID" column="grupo_id" identity="true" key="primary"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
<attribute name="Nome" column="grupo_nm"/>
<attribute name="Desc" column="grupo_dsc"/>
</class>
<association fromClass="Usuario"
toClass="MembroGrupo"
cardinality="oneToMany"
target="Grupos"
retrieveAutomatic="true"
deleteAutomatic="false"
saveAutomatic="false"
inverse="false">
<entry fromAttribute="UID" toAttribute="UserID"/>
</association>
<association fromClass="MembroGrupo"
toClass="Grupo"
cardinality="oneToOne"
target="Grupo"
retrieveAutomatic="true"
deleteAutomatic="false"
saveAutomatic="false"
inverse="false">
<entry fromAttribute="GID" toAttribute="GID"/>
</association>
</map>
and i'm trying to do the bind:
this.drpTeste.DataSource = AuthUser.Credenciais.Grupos;
this.drpTeste.DataBind();
where AuthUser.Credenciais.Grupos is a CPersistentCollection.
I'm tring to bind the Nome and GUI properties of Grupo's of the Usuario class to a dropdown lista, but i just can bind properties of the MebrosGrupo class.
Can i indirect bind it throug Grupo.Nome and Grupo.GID or should i procede any other way?
Thanks,
Claudio
I am trying use the object itself
Me.DataGridItems.DataSource = obj.DetallePedidoVenta
it is incorrect,
and
Me.DataGridItems.DataSource = obj.DetallePedidoVenta
it is incorrect
The problem is that the datagrid accept ArrayList
Usario.Grupos is a reference to a MembroGroupo class not a Grupo class.
This means the collection will contain MembroGrupo objects not Grupo objects.
I haven't tried the indirect binding and I'm not 100% sure of how the internals in databinding work but I'm pretty sure that binding works using first level property names only and does no parsing of the object name to handle nesting. I could be wrong so I would suggest that you try it first - or check on google, msdn, etc.
In any case, given the class map supplied I am assuming that you are actually wanting a Many-to-Many association between Usario and Grupo and that MembroGrupo is used only for managing the association.
If this is the case then I would suggest that you add a new collection to the Usario object for holding Grupo objects. As items get added and removed from the MembroGrupo collection (use events) simply add/remove the linked Grupo object from the new colelction. Then do databinding on the new Grupo collection instead of the MembroGrupo collection.
I would also recommend strongly typing the collections as it really helps with the databinding process when you want to use data grids, etc.
Let me know how if it works for you.
- Richard.
Hi Richard,
in fact, it's a OnetoMany association between the Usuario and Grupo classes. An Usuario (User) belongs to N Grupos (Groups). But i've changed the approach. I've included a propertie call Nome in the MembroGrupo class and there i load the Nome propertie of Grupo class at runtime.
But i've got some other questions.
There some simple task i wish to do but i'm not certain the way i should.
I 've seen how much development time we can gain using the Framework, but i figuring out some way to gain some more! :-p
Can you give some directions in:
1) Sorting CPersistentCollection.
Well, i wrote the class do return the MembroGrupo class, but when i bind it to a dropdown list, it comes out of order. Is there any quick way to do the sorting at the Collection?!
2) Search inside a Collection or Class;
When i create a Usuario Object, i often need to search within the MembroGrupo collection. Can i filter only the returned collection?
Well, i think it covers the most usual operations, that i didn't find any example in the FAQ or Nunits tests (or i think so).
Thanks for you help,
Claudio
1) Sorted collections
There's no supprot for sorted collections at this stage. The objects in the collection are ordered based on the way they are added.
Obviously you can subclass the CPersistentCollection yourself and add sorting, but you'll need to watch out for what happens when you have objects with multiple key fields, and how those fields should be ordered.
2) Searching in a collection
Once again, I haven't done anything in this regard. Assuming you only sort on key fields, searching efficiently depends on having a sorted collection.
Searching inefficiently is just a "for each" loop.
By the way, I think both ideas are good ideas. If you don't want to do the code yourself, just submit a tracker item for each in the feature requests. And if you do write the code, I'd love to see it.
- Richard.