Home - Forums-.NET - FlyGrid.Net (Windows Forms) - list item with a combobox from a ArrayList collection

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

list item with a combobox from a ArrayList collection
Link Posted: 23-Nov-2005 04:43
Hello!

I have problem with making an ArrayList to show it's items so one can be selected.


This InitAndFillGrid is called from Form1_Load and it looks like this.

private void InitAndFillGrid()
{
     colGrid.Columns.Items.Clear();
     DynamicallyAutoDetectDataTypeColumn autoColumn_1 = new      
          DynamicallyAutoDetectDataTypeColumn("Col1");
     colGrid.Columns.Items.AddRange( new Column[] {autoColumn_1} );
     dataSetList.Add( new object[] { SomeList.EmptyItem } );
     dataSetList.Add( new object[] { mySomeOptions } );  
     dataSetList.Add( new object[] { SomeList.ListItem2 } );      
     dataSetList.Add( new object[] { 1 } );  
     dataSetList.Add( new object[] { rawList } );
     dataSetList.Add( new object[] { SomeList.ListItem0 } )
     colGrid.Rows.DataSource = dataSetList;
}
In the class I do this
private ArrayList rawList;
and in the constructor I create an instance of the ArrayList and add some strings
rawList     = new ArrayList();
rawList.Add("aaa");
rawList.Add("bbb");
rawList.Add("ccc");


I have this rawList that contains of arbitrary number of strings(here just 3 strings).  I want to give the user the possibility to select one of these items in the collection by using a combobox.
Now to my question how do I display this rawList collection in a combobox so the user can select one?


If this rawList is an ArrayList I get an exception saying
"Object reference not set to an instance of an object"
dataSetList.Add( new object[] { rawList } );

//Tony
Link Posted: 23-Nov-2005 11:04
Take attention to the    
public enum SomeList
{
      EmptyItem = 0,
      ListItem0,
      ListItem1,
      ListItem2,
      ListItem3,
}

type.
DynamicallyAutoDetectDataTypeColumn columns use System.Reflection to extract TypeEditor and TypeConverter of data type displayed to provide convenient way for editing.
You can provide list of aaa,bbb,ccc by using
public enum ListOfStrings
{
      aaa,
      bbb,
      ccc
}

enum to provide this data with dropdown list.

If you'll provide:

[Flags]
[Editor(typeof(NineRays.Windows.Forms.Design.FlagsEnumEditor), typeof(System.Drawing.Design.UITypeEditor))]
public enum ListOfStrings
{
      empty = 0, //empty value
      aaa = 1,
      bbb = 2,
      ccc = 4
}


and replace
  dataSetList.Add( new object[] { rawList } );

by
  dataSetList.Add( new object[] { ListOfStrings.aaa } );


DynamicallyAutoDetectDataTypeColumn will shows dropdownlist wth checkboxes as NineRays.Windows.Forms.Design.FlagsEnumEditor provide this editor.

Please read MSDN about TypeConverterAttribute, Typeconverter, TypeEditor to expand DynamicallyAutoDetectDataTypeColumn editing functionality with universal data type editors and converters that  will work in standard PropertyGrid and FlyGrid.Net.
By this way you can provide dynamic list values in dropdown.

Additionally - see the VerticalGrid sample to see how FlyGrid and DynamicallyAutoDetectDataTypeColumn use power of System.Reflection and System.Design at runtime.
Link Posted: 23-Nov-2005 15:07
We've improved previous sample and made new one, download this C# sample, hope this project helps you to more clearly understand how to create design-time ready type, use Typeconverters and editors and provide different dropdown list for different cells.