读书人

怎么控制DataGridView自定义数据源的显

发布时间: 2012-01-07 21:41:55 作者: rapoo

如何控制DataGridView自定义数据源的显示顺序?
自定义一个类,如汽车类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的数据源,但得到的显示结果并不是理想的循序,请问我应该怎么改??谢谢

[解决办法]
做一个表.
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);
以表做为数据源
[解决办法]
你可以在DataGridView中自定义列呀,在邦定到列中
[解决办法]
数据源排序下再绑
[解决办法]
用模板编辑器

[解决办法]
如果你的表的列以后都是固定不定的,建议先建一个所有的列添加进一个表,动态构建表.然后有什么数据可以按照之前的顺序把数据写进去.
[解决办法]
up
[解决办法]
你说的顺序是列还是行?

读书人网 >C#

热点推荐