473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2077
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.