How can I allow my user to add more than 1 type of object to my collection, during design-time?
The default CollectionEditor will allow your user to add objects of type returned by your collection’s indexer method. You can make this CollectionEditor allow your user to pick the type of object to add by deriving from CollectionEditor and making the change as shown below. This will introduce a drop-down in the editor’s ‘Add’ button to allow the user to pick the type he wants to add. public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor { private Type[] types; public CustomCollectionEditor(Type type) : base(type) { types = new Type[]{typeof(ItemType1), typeof(ItemType2), typeof(ItemType3), typeof(ItemType4)}; } // Return the types that you want to allow the user to add into your collection. protected override Type[] CreateNewItemTypes() { return types; } } [Editor(typeof(CustomCollectionEditor), typeof(UITypeEditor))] public class CustomCollection : IList { … }
I am populating a ListBox by binding it to an ArrayList. The initial display is OK, but later changes to my ArrayList are not shown in my ListBox. How can I get the changes to show properly
In an ArrayList, the ’plumbing’ is not available to support two-way binding as with a dataset. So, you have to handle the synchronization yourself. One way to do this is to set the listBox1.DataSource to null and then reset it to your ArrayList. Another way is to use the CurrencyManager as shown in the code below. private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button button1; private ArrayList myArrayList; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); myArrayList = new ArrayList(); myArrayList.Add(‘orange’); myArrayList.Add(‘green’); myArrayList.Add(‘blue’); myArrayList.Add(‘red’); listBox1.DataSource = myArrayList; } …… //change the arraylist private void button1_Click(object sender, System.EventArgs e) { myArrayList[1] = ‘pink’; myArrayList.Add(‘lavendar’); //use currency manger to sync up the listbox BindingManagerBase bm = this.listBox1.BindingContext[myArrayList]; CurrencyManager cm = (CurrencyManager) bm; if (cm != null) cm.Refresh(); //Or, you can just reset the datasource //listBox1.DataSource = null; //listBox1.DataSource = myArrayList; }
How do I make a field auto increment as new rows are added to my datagrid
DataTable myTable = new DataTable(‘Customers’); … DataColumn cCustID = new DataColumn(‘CustID’, typeof(int)); cCustID.AutoIncrement = true; cCustID.AutoIncrementSeed = 1; cCustID.AutoIncrementStep = 1; myTable.Columns.Add(cCustID);
I have a form with several controls on it. As I size the form, the controls are being resized continuously. Is it possible to postpone changing the controls position until the resizing is complete
Shawn Burke suggested this solution in a response on the microsoft.public.dotnet.framework.windowsforms newsgroup. The idea is to do the painting on Idle. This means you simple invalidate when being sized and then do your full paint when the size completes. Here is the code that you would add to your form. bool idleHooked = false; protected override void OnResize(EventArgs e) { if (!idleHooked) { Application.Idle += new EventHandler(OnIdle); } } private void OnIdle(object s, EventArgs e) { Invalidate(); PerformLayout(); if (idleHooked) { Application.Idle -= new EventHandler(OnIdle); } }
How can I see what is installed in the Global Assembly on a machine
Use Windows Explorer to view the C:\WINNT\assembly folder. If the .NET Framework is installed, the Windows Explorer will show a custom view of this folder. Use the detailed view to see the details of each assembly.