How do you implement TopLevel Controls
TopLevel controls (like Form) cannot be added into Controls list using Controls.Add(). For example, if you are trying to add a form into a Panel’s control list, it will lead you to an exception ‘Top-level control cannot be added to a control’. To avoid this exception, you need to set the form’s TopLevel property to false. Form form2 = new Form(); form2.TopLevel = false; this.panel1.Controls.Add(form2);
In VB.NET how do I access the runtime type object of a specified type from it’s type name?
Visual Basic has a GetType operator that can be used to obtain the System.Type object for the specified type name. This is the equivalent of the typeof keyword in C#. ’ Returns the System.RuntimeType object representing the integer type. Dim inttype As Type = GetType(Integer) ’ Returns the System.RuntimeType object representing the Project1.Type1 class. Dim mytype As Type = GetType(Project1.Type1)
Is there a way to access private and protected members of a class instance?
.NET Reflection can be used to get hold of non-Public members of a class instance. The System.Type class provides various methods that allow you to access the fields/properties/methods for all defined types. Depending on the context, you can use either the typeof(class) operator or the Object.GetType() method to get hold of the System.Type object representing the particular type and then use that type object to access the required member information. The following code shows how to use the Type.GetField() and FieldInfo.GetValue() methods to determine the value of the ’pasteIndex’ private field implemented by the Diagram.Controller class. // In C#.NET // Use Reflection to access the this.ActiveDiagram.Controller object’s pasteIndex private member Type typecontroller = typeof(Syncfusion.Windows.Forms.Diagram.Controller); System.Reflection.FieldInfo finfo = typecontroller.GetField(‘pasteIndex’, BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.GetField); int npasteindex = 0; if(finfo != null) npasteindex = (int)finfo.GetValue(this.ActiveDiagram.Controller); ’ In VB.NET ’ Use Reflection to access the Me.ActiveDiagram.Controller object’s pasteIndex private member Dim typecontroller As Type = GetType(Syncfusion.Windows.Forms.Diagram.Controller) Dim finfo As FieldInfo = typecontroller.GetType().GetField(‘pasteIndex’, BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.GetField) Dim npasteindex As Integer = 0 If Not finfo Is Nothing Then npasteindex = finfo.GetValue(Me.ActiveDiagram.Controller) End If
How do I bind the values of an enum to a ComboBox?
This entry was created using the feedback provided by Jay Harlow in the newsgroups. The enum values can be bound to a combobox as follows: [C#] // Setup the binding as follows: // MyValues is the enum type comboBox1.DataSource = Enum.GetValues(typeof MyValues); [VB] comboBox1.DataSource = Enum.GetValues(Type.GetType(MyValues)) Then in the SelectedValueChanged event for the ComboBox. [C#] private void ComboBox1ValueChanged(object sender, EventArgs e) { MyValues v = (MyValues)this.comboBox1.SelectedValue; } [VB] Private Sub ComboBox1ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Dim v As MyValues = CType(Me.comboBox1.SelectedValue, MyValues) End Sub
How do I unselect the selected items in a ListView programatically?
Simply do the following: this.listView1.SelectedItems.Clear(); [C#] [VB] Me.listView1.SelectedItems.Clear()