像如下的类
private class nums
{
private int _n1,_n2,_n3,_n4; 
public int N1
{
get { return _n1;}
set { _n1 = value;}
}public int N2
{
get { return _n2;}
set { _n2 = value;}
}public int N3
{
get { return _n3;}
set { _n3 = value;}
}public int N4
{
get { return _n4;}
set { _n4 = value;}
}
}
我在程序中,用如下代码绑定数据
nums[] MyArray = new nums[3];
...//对MyArray进行操作
dataGrid1.DataSource = MyArray;
本希望在dataGrid中能按照N1,N2,N3,N4的顺序现实数据,但是却是按照N4,N1,N2,N3的顺序显示,不知道有没有什么办法可以解决这个问题。各位仁兄帮个忙

解决方案 »

  1.   

    不知道怎么改变nums字段排序,但是改变datagird的列的顺序应该没有问题吧?
      

  2.   

    列不自动帮定,在ASPX做BOUNDCOLUMN绑定总是按顺序的
      

  3.   

    将实现了ILis的对象绑定到数据源上的问题private class nums,有实现ILis吗?To:kfc0093(jack)晕,没人回答!
    还好自己搞定了!
    给自己加分了!???
      

  4.   

    晕,这个对象不是后来作用于数组了嘛。别告诉我你不知道数组继承于IList
      

  5.   

    说明一下,做的不是ASPX.DataGrid用的是Form下的
      

  6.   


    请恕愚顿,看你的问题,自觉的确是有nums实现ILis接口的歧义
      

  7.   

    不要用自动生成列就行了,自己排列。如果非要用,就自己写个Collection实现IListSource
      

  8.   

    MSDN上面没有关于ITypedList的例子,能不能给个例子学习一下
      

  9.   

    ITypedList,也仅仅把绑定列的过程从实体移至集合类,但是也无法提供顺序标示。。郁闷
      

  10.   

    public class RowData
    {
    public string product_id;
    public string product_nm;
    public string Product_id
    {
    get{return product_id;}
    set{product_id = value;}
    }
    public string Product_nm
    {
    get{return product_nm;}
    set{product_nm = value;}
    }public RowData(string id,string des)
    {
    this.Product_id=id;
    this.Product_nm=des;
    }
    }class RowDataCollection:CollectionBase
    {
    public RowData this[ int index ]  
    {
    get  
    {
    return( (RowData) List[index] );
    }
    set  
    {
    List[index] = value;
    }
    }public int Add( RowData value )  
    {
    return( List.Add( value ) );
    }public int IndexOf( RowData value )  
    {
    return( List.IndexOf( value ) );
    }public void Insert( int index, RowData value )  
    {
    List.Insert( index, value );
    }public void Remove( RowData value )  
    {
    List.Remove( value );
    }public bool Contains( RowData value )  
    {
    // If value is not of type RowData, this will return false.
    return( List.Contains( value ) );
    }protected override void OnInsert( int index, Object value )  
    {
    if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
    throw new ArgumentException( "value must be of type RowData.", "value" );
    }protected override void OnRemove( int index, Object value )  
    {
    if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
    throw new ArgumentException( "value must be of type RowData.", "value" );
    }protected override void OnSet( int index, Object oldValue, Object newValue )  
    {
    if ( newValue.GetType() != Type.GetType("WebApplication1.RowData") )
    throw new ArgumentException( "newValue must be of type RowData.", "newValue" );
    }protected override void OnValidate( Object value )  
    {
    if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
    throw new ArgumentException( "value must be of type RowData." );
    }}class Test
    {
    private RowDataCollection m_RowDataCollection;
    public RowDataCollection RowCollection
    {
    set{m_RowDataCollection=value;}
    get{return m_RowDataCollection;}
    }public void LoadData()
    {
    this.RowCollection=new RowDataCollection();
    this.RowCollection.Add(new RowData("7201","aaaaaa"));
    this.RowCollection.Add(new RowData("7202","aaaaaa"));
    this.RowCollection.Add(new RowData("7203","aaaaaa"));
    this.RowCollection.Add(new RowData("7204","aaaaaa"));
    }
    }private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    Test t=new Test();
    t.LoadData();
    RowData rd=t.RowCollection[1];
    this.DataGrid1.DataSource=t.RowCollection;
    this.DataGrid1.DataBind();
    }<asp:DataGrid id="DataGrid1" runat="server" Width="529px" Height="208px" AutoGenerateColumns="False">
    <Columns>
    <asp:BoundColumn HeaderText="a1" DataField="product_id"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="a2" DataField="product_nm"></asp:BoundColumn>
    </Columns>
    </asp:DataGrid>
      

  11.   

    http://community.csdn.net/Expert/topic/4565/4565698.xml?temp=.2365686
      

  12.   

    楼上这位仁兄,你的代码只是在ASP.NET中好用,可我要的是在form应用程序中的。