472,986 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Binding ArrayList full of custom objects to DataGrid

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
then add a DataGridTextBoxColumn for each of the properties in my custom
class which define a MappingName --> property name in class as well as
header text.
When I run the form, I see correct number of rows displayed, but none of the
columns appear. What am I missing?

Thank you in advance!

Berg

private void BindArrayListToGrid(IList results)

{

searchResults.DataSource = results;

DataGridTableStyle ts = new DataGridTableStyle();

ts.MappingName = "ArrayList";

int colwidth = (searchResults.ClientSize.Width

- ts.RowHeaderWidth

- SystemInformation.VerticalScrollBarWidth - 5) / 2;

// Create a column for the "districtKey" property

// defined in the districtKey Class

DataGridTextBoxColumn cs = new DataGridTextBoxColumn();

cs.MappingName = "districtKey"; // Public property name

cs.HeaderText = "District Key";

cs.Format = "f4";

cs.Width = colwidth;

ts.GridColumnStyles.Add(cs);

// Create a column for the "Telephone" property

// defined in the Telephone Class

cs = new DataGridTextBoxColumn();

cs.MappingName = "Telephone"; // Public property name

cs.HeaderText = "Telephone";

cs.Format = "f4";

cs.Width = colwidth;

ts.GridColumnStyles.Add(cs);

// Add the custom tablestyle to the DataGrid

searchResults.TableStyles.Clear();

searchResults.TableStyles.Add(ts);

}
Nov 16 '05 #1
0 1648

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

Similar topics

5
by: K | last post by:
I created a collection which is derived from ArrayList and implements IBindingList and ITypedList. Then I bound the DataSource of a data grid into the collection. It could show up the data but...
5
by: Dalibor Kusic | last post by:
The DataTable contains, for example, only one column of lets say Person class. Person class has three fields, and a constructor that takes a single string and parses it over those three fields. ...
3
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...
0
by: Terentius Neo | last post by:
I have binded a DataGrid to a custom hierarchy. It is an ArrayList of objects. Each object has a public property returning a new ArrayList of sublevel objects (which may again have sublevels of...
5
by: Alex Nitulescu | last post by:
Hi. I'm fighting the following code: __________________________________________________________________________ a. I have a class UserInfo.vb: <Serializable()> Public Class UserInfo Public...
3
by: Jim Bancroft | last post by:
Hi everyone, I'm binding an ArrayList to a DataGrid for the first time (I'm used to binding DataSets and DataTables) and I was wondering if I could somehow "name" the ArrayList, so that I can...
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...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
2
by: Merk | last post by:
I'm new to .NET (using 2.0) and was wondering how to go about binding a collection of custom classes to a DataGrid. The class exposes 5 read-only String properties. I would like for each of...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.