PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework help: customize CF2.0 DataGrid when bind with BindingList<Business Object>?

Reply

help: customize CF2.0 DataGrid when bind with BindingList<Business Object>?

 
Thread Tools Rate Thread
Old 21-06-2007, 09:48 AM   #1
Chen Naikun
Guest
 
Posts: n/a
Default help: customize CF2.0 DataGrid when bind with BindingList<Business Object>?


hi,

I have difficulty on how to customize CF2.0 DataGrid bind with
BindingList<Business Object>.

I have a customer type :
internal class Customer
{
private Guid _id;
private int _name;

public Guid ID
{
get{return _id;}
set { _id = value; }
}

public string Name
{
get{return _name;}
set{_name=value;}
}
}

in windows form, i don't want display the property id to user, i have tried
this:
public partial class datagridtest : Form
{
private System.ComponentModel.BindingList<Customer> _list = new
BindingList<testClass>();

public datagridtest()
{
InitializeComponent();
dataGrid1.DataSource = _list;

//dataGrid1.TableStyles.Clear();

DataGridTableStyle tableStyle1 = new DataGridTableStyle();

DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();
columnStyle.HeaderText = "Name";
columnStyle.MappingName = "Name";
tableStyle1.GridColumnStyles.Add(columnStyle);

dataGrid1.TableStyles.Add(tableStyle1);

}

private void datagridtest_Load(object sender, EventArgs e)
{

for(int i = 0 ; i < 10; i++)
{
Customer c = new Customer();
c.ID = System.Guid.NewGuid();
c.Name= "Naikun";

_list.Add(test);
}
}
}

but when form showed, the grid have two columns, one is ID,the other one is
Name!

any help is apprecied




  Reply With Quote
Old 23-06-2007, 03:47 AM   #2
Chen Naikun
Guest
 
Posts: n/a
Default Re: customize CF2.0 DataGrid when bind with BindingList<Business Object>?

I have resoled this problem : the MappingName should be "BindingList`1"!

the InitializeComponent() code like this:

//
// dataGrid1
//
this.dataGrid1.BackgroundColor =
System.Drawing.Color.FromArgb(((int)(((byte)(128)))),
((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.dataGrid1.Location = new System.Drawing.Point(17, 16);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(258, 200);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.Add(this.dataGridTableStyle1);
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn1);
this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn2);
this.dataGridTableStyle1.MappingName = "BindingList`1";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Code";
this.dataGridTextBoxColumn1.MappingName = "Code";
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "Name";
this.dataGridTextBoxColumn2.MappingName = "Name";


public partial class datagridtest : Form
{
private System.ComponentModel.BindingList<Customer> _list = new
BindingList<Customer>();

public datagridtest()
{
InitializeComponent();

}

private void datagridtest_Load(object sender, EventArgs e)
{
for(int i = 0 ; i < 10; i++)
{
Customer c = new Customer();
c.ID = System.Guid.NewGuid();
c.Name= "Naikun";
c.Code="C01";

_list.Add(c);
}

dataGrid1.DataSource = _list;
}
}

"Chen Naikun" <naikun@163.com> дÈëÏûÏ¢ÐÂÎÅ:eriSPC%23sHHA.1208@TK2MSFTNGP03.phx.gbl...
> hi,
>
> I have difficulty on how to customize CF2.0 DataGrid bind with
> BindingList<Business Object>.
>
> I have a customer type :
> internal class Customer
> {
> private Guid _id;
> private int _name;
>
> public Guid ID
> {
> get{return _id;}
> set { _id = value; }
> }
>
> public string Name
> {
> get{return _name;}
> set{_name=value;}
> }
> }
>
> in windows form, i don't want display the property id to user, i have
> tried this:
> public partial class datagridtest : Form
> {
> private System.ComponentModel.BindingList<Customer> _list = new
> BindingList<testClass>();
>
> public datagridtest()
> {
> InitializeComponent();
> dataGrid1.DataSource = _list;
>
> //dataGrid1.TableStyles.Clear();
>
> DataGridTableStyle tableStyle1 = new DataGridTableStyle();
>
> DataGridColumnStyle columnStyle = new DataGridTextBoxColumn();
> columnStyle.HeaderText = "Name";
> columnStyle.MappingName = "Name";
> tableStyle1.GridColumnStyles.Add(columnStyle);
>
> dataGrid1.TableStyles.Add(tableStyle1);
>
> }
>
> private void datagridtest_Load(object sender, EventArgs e)
> {
>
> for(int i = 0 ; i < 10; i++)
> {
> Customer c = new Customer();
> c.ID = System.Guid.NewGuid();
> c.Name= "Naikun";
>
> _list.Add(test);
> }
> }
> }
>
> but when form showed, the grid have two columns, one is ID,the other one
> is Name!
>
> any help is apprecied
>
>
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off