Binding HashTable to datagridview

P

plmanikandan

Hi,
I am using .net framework2.0,Visual Studio 2005.I need to bind the hash
table to datagridview.Is it possible
I am having class Person
class person
{
public int no;
public string name;
}

person a=new person();
a.no=100;
a.name="ffg";
I need to add obj a as both key and value
Hashtable ht = new Hashtable();
ht.add(a,a);
dataGridView1.DataSource = ht;
When I bind the Hashtable to datagridview,it is not showing anything in
datagridview.Is it possible to bind Hashtable to datagridview.Kindly
provide me the steps to bind hashtable to datagridview.

Regards,
Manikandan
 
C

chanmm

Try this:

dataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect;
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ht;

chanmm
 
P

plmanikandan

Hi,
I tried the code as below

Hashtable ht = new Hashtable();
for (int x = 0; x < 10; x++)
{

Class1 a = new Class1();
a.a = x;
a.str = "ff";
ht.Add(a, a);
}
dataGridView1.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ht;

When i run the above code,nothing is diaplayed in
datagridView.DatagridView is empty only

Mani
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top