在pocketpc 上通过bindingsource 在DataGrid显示数据。
但是现在无法订制datagrid的各个列。
不说了直接上代码。
1.DataObject : namespace SmartPhoneProjectAboutDataBinding
{
   class Data
   {
      public Data(String name,string id,int age)
      {
         this.name = name;
         this.id = id;
         this.age = age;
      }
      private string name;      public string Name
      {
         get { return name; }
         set { name = value; }
      }
      private string id;      public string Id
      {
         get { return id; }
         set { id = value; }
      }      private int age;      public int Age
      {
         get { return age; }
         set { age = value; }
      }
}2 DataGrid and bindingsource
private System.Windows.Forms.DataGrid dataGrid .... ; (不要说怎么不用 DataGridView,在.netCF 中没有 DataGridView)
private System.Windows.Forms.BindingSource dataBindingSource;
.....
this.dataBindingSource.DataSource = typeof(SmartPhoneProjectAboutDataBinding.Data);
...
this.dataGrid.DataSource = this.dataBindingSource;
....
BindingList<Data> dataList = new BindingList<Data>(); 
//Add Data to dataList 
dataList.Add(new Data(...));this.dataBindingSource.DataSource = dataList;到现在为止 Datagrid 能够正常显示 Datalist中的所有数据。但是 通过 // 
         // dataGridTableStyle1
         // 
         this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn1);
         this.dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn2);
...
         this.dataGridTableStyle1.MappingName = "Data";
来设置各个列的标题和width时没有任何效果。

解决方案 »

  1.   

    DataGrid控件功能做的不是很好,搂主可以用DataGridView控件
      

  2.   


    private System.Windows.Forms.DataGrid dataGrid .... ; (不要说怎么不用 DataGridView,在.netCF 中没有 DataGridView
      

  3.   

    既然这样,那搂主必须在查询的时候转换数据类型比如:如果原来是bit类型的,也就是boolean类型的字段,
    那么在查询的时候就应该这样做:
    select cast(布尔字段 as varchar) from table_name
    这样就可以了。客户端DataGridView绑定数据源之后,是没法修改列的类型的!除非像我上面几楼说的那样变通一下修改。
      

  4.   

    csdn上回帖的质量真是.... 
    哎,问题都没有看清楚.===贴一段MSDN上的回帖来解答这个问题吧。DataGridTableStyle.MappingName should be set to one of the following based on your DataSource:1. DataTable.TableName if source is DataTable (or DataView).2. String.Empty if source is SqlCeResultSet.3. list.GetType().Name for any IList collection, e.g. an array. You also must set column stiles with proper mapping names (which are column names for DataTable and SqlCeResultSet, property name on a class which represent row in the collection) for all the columns you want to see in the grid. If you don’t want to see a column then simply don’t set a column style for it. Also remember what mapping names are case sensitive. Common issues and reasons: 1.       Table style is set but has no effect. Reason: wrong mapping name. Make sure to set mapping name properly.2.       No column are shown as soon as table style is set. Reason: table style mapping name is set correctly but no column styles are set or column mapping styles are set incorrectly. Make sure to set column styles with correct mapping names for each column you want to show.
      

  5.   

    不好意思,愚人回的是下面贴的,回错地方给兄弟造成麻烦了:
    http://topic.csdn.net/u/20081202/17/aee68a19-7008-4fc4-8cf0-972e5c1bf437.html
      

  6.   

    dataGridTableStyle1.MappingName = dataBindingSource.GetListName(null); 
    这样就ok了