473,511 Members | 15,364 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList of custom classes as Datagrid's DataSource

Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #1
5 2084
Hi,

Is this a web or win app ?
I have done this for a web app, don't think it will work in a win app
though.
Here is the code:

You see I have to cast the DataItem to teh correct type to have access to
the properties

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="117"
ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<span ><%# ((CtpRecord)Container.DataItem).Locations.Count==0 ?"Not set":
((CtpRecord)Container.DataItem).Locations[0].LocalName%></span>
</itemtemplate>
</asp:templatecolumn>

This is a column which require some extra processing hence I use a method
declared as protected string GetFirstDocumentOfRecord in the code behind

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="110"
ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<span ><%# GetFirstDocumentOfRecord((CtpRecord)Container.Data Item)
%></span>
</itemtemplate>
</asp:templatecolumn>
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #2
Hi,

Is this a web or win app ?
I have done this for a web app, don't think it will work in a win app
though.
Here is the code:

You see I have to cast the DataItem to teh correct type to have access to
the properties

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="117"
ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<span ><%# ((CtpRecord)Container.DataItem).Locations.Count==0 ?"Not set":
((CtpRecord)Container.DataItem).Locations[0].LocalName%></span>
</itemtemplate>
</asp:templatecolumn>

This is a column which require some extra processing hence I use a method
declared as protected string GetFirstDocumentOfRecord in the code behind

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="110"
ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<span ><%# GetFirstDocumentOfRecord((CtpRecord)Container.Data Item)
%></span>
</itemtemplate>
</asp:templatecolumn>
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi guys, I've been reading several topics that talk about creating a
custom collection to use it as DataSource of a Datagrid.

But the fact is I have a class called Action and another class called
Profile. In my application, the user assigns several Actions to a
Profile. I thought doing this using an ArrayList of Actions and puting
that as the DataSource of the Datagrid that shows the assignments. It
works, but it shows every property Action class have.

My two questions are:
1) how can I choose the properties of Action class I want to be
bounded?
2) does it sound reasonable? I mean the ArrayList of my custom class
Action...

Thanks in advance,
Damian

Nov 17 '05 #3
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #4
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #5
Hi,

Ok, then the piece of code I gave you fills well , you select the
properties you want to show, you use a templacecolumn for that.

one question though, all the elements of the arraylist are of the same type
right?
just use teh code I gave you or let me know if you have any problem.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<dl******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Ignacio:

It's all on a web app. Maybe I didn't express myself clearly.

I want to implement some kind of interface to tell the data Grid which
properties he has to take from each object in the ArrayList.

I don't know if that's possible.

Thanks,
Dam

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3867
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I...
7
455
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
0
1678
by: berg | last post by:
All, I am binding an ArrayList full of custom objects to an DataGrid. The property in the custom class are all public. I define a DataGridTableStyle and set the MappingName to "ArrayList". I...
2
7803
by: Stephen | last post by:
I am trying to delete a row in a datagrid on the onclick of a asp:ButtonColumn. The datagrid is created from the items in an arraylist so what im trying to do is remove the item from the array and...
3
2840
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
0
357
by: dlobalzo | last post by:
Hi guys, I've been reading several topics that talk about creating a custom collection to use it as DataSource of a Datagrid. But the fact is I have a class called Action and another class called...
5
4851
by: Rami | last post by:
Hey, I Tried to bind a DataGrid to an ArrayList, and had 2 problems: 1. The DataGrid shows the Length property of the items instead of their text - how can I change that? 2. After binding, I add...
16
2004
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a...
0
1232
by: Marcus Kwok | last post by:
I am having a weird problem with my DataGrid that is bound to an ArrayList. My situation is as follows: I have two DataGrids on a modal form. The top grid populates an ArrayList from a file,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.