locked
DataGrid AutoSort and SingleRowSelection when DataSource is an ArrayList RRS feed

  • Question

  • Hi,

    I am using a DataGrid control on my form which is filled by an ArrayList. After that I clear DataGridTableStyle and add the customized one. But after adding DataGridTableStyle, the Grid's AutoSorting functionality does not work. Eventhough set AutoSort=true.

    1. Can anybody tell me what to do to achieve AutoSorting by clicking on column header?
    2. Also How may I restrict the users to Select Single row only?

    Following is a small snippet of code I use:

    1             // myArrayList is filled before with my Business Objects  
    2             this.dataGrid1.DataSource = myArrayList;  
    3  
    4             DataGridTableStyle t = new DataGridTableStyle ();  
    5             t.MappingName= "ArrayList";           
    6                   
    7             DataGridTextBoxColumn c = new DataGridTextBoxColumn ();  
    8             c.MappingName = "Id";  
    9             c.HeaderText="ID";  
    10             t.GridColumnStyles.Add (c);  
    11  
    12             c =  new DataGridTextBoxColumn ();  
    13             c.MappingName = "Reference";  
    14             c.HeaderText="Reference";  
    15             t.GridColumnStyles.Add (c);  
    16  
    17             this.dataGrid1.TableStyles.Clear();  
    18             t.AllowSorting = true;            
    19             this.dataGrid1.TableStyles.Add (t);  
    20  
    21  

     


    Interface Mirror
    Thursday, March 12, 2009 5:18 AM

Answers

  • Hi Jandost,

    As for your first question, you need to implement the IBindingList interface on the data source to make it sortable.

    As for your second question, there's no way to restrict the user to select single row only. But the current row in a DataGrid is always single.

    Hope this helps.
    If you have any question, please feel free to let me know.

    Sincerely,
    Linda Liu

    • Marked as answer by Linda Liu Wednesday, March 18, 2009 4:48 AM
    Monday, March 16, 2009 7:31 AM