473,387 Members | 1,493 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,387 software developers and data experts.

DataGrid and ArrayList binding

I created a simple Person class as following:

class Person{
private string fname;
private string lname;

public Person(string fname, string lname){
this.fname = fname;
this.lname = lname;
}

public string FirstName{
get{return this.fname;}
set{this.fname = value;}
}

public string LastName{
get{return this.lname;}
set{this.lname = value;}
}
}

-- I create Person ArrayList
ArrayList pList = new ArrayList();
pList.Add(new Person("Jame","C."));
pList.Add(new Person("Jonh","D."));

-- binding to datagrid
dataGrid1.DataSource = pList;

-- select data grid row and get back the selected Person object.
How can I complete this stage?

Regards,
Kids
Nov 17 '05 #1
2 1949
Kids,

If you use a datatable in C# for Net 1.1 than you get all functionality from
the datagrid.
With an arraylist you get that just partially.

To create a datatable in your sample is nothing more than

DataTable dt = new DataTable(Persons);
dt.Columns.Add("FirstName");
dt.Columns.Add("LastName");
dt.Rows.LoadDataRow(new Object() {"Jame","C"},true);
dt.Rows.LoadDataRow(new Object() {"John","D"},true);
dataGrid1.DataSource = dt;

Watch typos, I have typed it in directly in this message without a layer.

I hope this helps,

Cor

"kids_pro" <ki******@yahoo.com> schreef in bericht
news:e%****************@TK2MSFTNGP12.phx.gbl...
I created a simple Person class as following:

class Person{
private string fname;
private string lname;

public Person(string fname, string lname){
this.fname = fname;
this.lname = lname;
}
public string FirstName{
get{return this.fname;}
set{this.fname = value;}
}

public string LastName{
get{return this.lname;}
set{this.lname = value;}
}
}

-- I create Person ArrayList
ArrayList pList = new ArrayList();
pList.Add(new Person("Jame","C."));
pList.Add(new Person("Jonh","D."));

-- binding to datagrid
dataGrid1.DataSource = pList;

-- select data grid row and get back the selected Person object.
How can I complete this stage?

Regards,
Kids

Nov 17 '05 #2
Hi,

"kids_pro" <ki******@yahoo.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
I created a simple Person class as following:

class Person{
private string fname;
private string lname;

public Person(string fname, string lname){
this.fname = fname;
this.lname = lname;
}
public string FirstName{
get{return this.fname;}
set{this.fname = value;}
}

public string LastName{
get{return this.lname;}
set{this.lname = value;}
}
}

-- I create Person ArrayList
ArrayList pList = new ArrayList();
pList.Add(new Person("Jame","C."));
pList.Add(new Person("Jonh","D."));

-- binding to datagrid
dataGrid1.DataSource = pList;

-- select data grid row and get back the selected Person object.
How can I complete this stage?
Get the selected person:

Person p = (Person) dataGrid1.BindingContext[pList].Current;

HTH,
Greetings


Regards,
Kids

Nov 17 '05 #3

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

Similar topics

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: guy | last post by:
I have a winforms datagrid bound to an arraylist which works correctly, however if I add a row to the arraylist i cannot get the datagrid to display the updated data other than by:- clearing the...
0
by: guy | last post by:
I have a winforms datagrid bound to an arraylist which works correctly, however if I add a row to the arraylist i cannot get the datagrid to display the updated data other than by:- clearing the...
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.