自定义一个类,如汽车类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的数据源,但得到的显示结果并不是理想的循序,请问我应该怎么改??谢谢
{
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的数据源,但得到的显示结果并不是理想的循序,请问我应该怎么改??谢谢
解决方案 »
- 关于hashtable与数据库表操作的问题
- 蓝牙连接检查的问题
- 把excel转换成sql时打开excel和没打开excel读出来的datatable行数是不一样的??
- 如何在VS中创建MASM程序,有着色的那种?
- WPF浏览器应用程序发布以后怎么会生成两份.net框架安装文件
- 如何取得摄像头视频数据流?不要保存,我需要使用socket发送到目标服务端
- 各位如果把数据库中的存储过程当做类来处理如何?
- 做一个C/S结构的系统,客户端和服务器端一般采用何种连接方式?Remoting?TCP?
- 运算符归类的问题
- DEV控件怎么绑定dataset的数据啊?
- 第一次来这里问问题,关于c# Winforms的 画图问题
- 急求读取dll文件版本号(.net下面编译的)
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);
以表做为数据源
不是这样的.我是想用自定义类作为Row来展示数据,因为要经常传递数据,所以不能像你那样写.
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;