if (ds!=null)
            {
                this.dataGrid1.DataSource = ds;
            }            DataGridTableStyle Datadt = new DataGridTableStyle();
            Datadt.MappingName = ds.Tables[0].TableName;
            DataGridColumnStyle w_id = new DataGridTextBoxColumn();
            w_id.MappingName = "w_id";
            w_id.HeaderText = "妇女编号";
            w_id.Width = 15;
            Datadt.GridColumnStyles.Add(w_id);
            DataGridColumnStyle wname = new DataGridTextBoxColumn();
            w_id.MappingName = "name";
            w_id.HeaderText = "妇女姓名";
            w_id.Width = 30;
            Datadt.GridColumnStyles.Add(wname);
            dataGrid1.TableStyles.Add(Datadt);
ds中不是空的,可是dataGrid显示不出数据来,请问哪位高手可以帮帮忙,急急急

解决方案 »

  1.   

    帮你调试好了。呵呵!给你调试代码。我第一次搞windows mobile上的程序
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace DeviceApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
            {
                
            }        private void button1_Click(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                DataTable ct1 = new DataTable("ct1");
                ds.Tables.Add(ct1);
                ds.Tables["ct1"].Columns.Add("w_id", typeof(string));
                ds.Tables["ct1"].Columns.Add("name", typeof(string));
                DataRow dr = ct1.NewRow();
                dr[0] = "1";
                dr[1] = "花花";
                ct1.Rows.Add(dr);            DataGridTableStyle Datadt = new DataGridTableStyle();
                Datadt.MappingName = ds.Tables[0].TableName;
                DataGridColumnStyle w_id = new DataGridTextBoxColumn();
                w_id.MappingName = "w_id";
                w_id.HeaderText = "妇女编号";
                w_id.Width = 60;
                Datadt.GridColumnStyles.Add(w_id);
                DataGridColumnStyle wname = new DataGridTextBoxColumn();
                wname.MappingName = "name";
                wname.HeaderText = "妇女姓名";
                wname.Width = 60;
                Datadt.GridColumnStyles.Add(wname);
                dataGrid1.TableStyles.Add(Datadt);            if (ds != null)
                {
                    this.dataGrid1.DataSource = ds.Tables[0];
                }
                
            }
        }
    }