自定义一个类,如汽车类Car,如:    class Car
    {
        private string _carId = string.Empty;
        private double _carX = 0.0;
        private double _carY = 0.0;
        private double _speed = 0.0;
        private string _azimuth = string.Empty;        public Car(string carId, double x, double y, double speed)
        {
            this._carId = carId;
            this._carX = x;
            this._carY = y;
            this._speed = speed;
        }        public string CarId
        {
            get
            {
                return this._carId;
            }
        }        public double x
        {
            get
            {
                return this._carX;
            }
        }        public double y
        {
            get
            {
                return this._carY;
            }
        }        public double Speed
        {
            get
            {
                return this._speed;
            }
        }        public string Azimuth
        {
            get
            {
                return this._azimuth;
            }
        }        public string Status
        {
            get
            {
                return this._speed <= 0.0 ? "停泊" : "行驶中";
            }
        }
    }提供了汽车的当前属性,我想按照车号,位置,速度,方向等顺序在DataGridView中显示数据,于是先将一部分汽车实体添加到ArrayList中,并设置DataGridView的数据源,但得到的显示结果并不是理想的循序,请问我应该怎么改??谢谢

解决方案 »

  1.   

    做一个表.
    DataTable dt=new DataTable ();
    dt.Columns .Add ("name",System .Type .GetType("System.String"));
    dt.Columns .Add ("id",System .Type .GetType ("System.Int32"));
    DataRow dr=dt.NewRow ();
    dr[0]="新表";
    dr["id"]=1;
    dt.Rows .Add (dr);
    DataRow dr1=dt.NewRow ();
    dr1[0]="旧表";
    dr1["id"]=0;
    dt.Rows .Add (dr1);
    以表做为数据源
      

  2.   

    cbgn(小玉):
    不是这样的.我是想用自定义类作为Row来展示数据,因为要经常传递数据,所以不能像你那样写.
      

  3.   

    ArrayList ds = new ArrayList();
    ds.Add(new Car("京A0001", 114.56, 22.3, 76.6);
    ds.Add(new Car("京A0002", 114.56, 22.3, 76.6);
    ds.Add(new Car("京A0003", 114.56, 22.3, 76.6);
    DataGridView1.DataSource = ds;
      

  4.   

    你可以在DataGridView中自定义列呀,在邦定到列中
      

  5.   

    怎么自定义列啊?在Columns编辑器中吗??不行,这种方法我试过的...邦定后结果为自定义列+邦定数据列.有没有其他办法?
      

  6.   

    DataGridView属性,行为里,有一个autoGenerateColumns运行时是否用绑定的数据生成列,把它设置成假