By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,571 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,571 IT Pros & Developers. It's quick & easy.

DataGrid and ArrayList binding

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.