background preloader

C#.NET

Facebook Twitter

IComparable-Schnittstelle (System) [ComVisibleAttribute(true)] public interface IComparable Der IComparable-Typ macht die folgenden Member verfügbar. using System; using System.Collections; public class Temperature : IComparable { // The temperature value protected double temperatureF; public int CompareTo(object obj) { if (obj == null) return 1; Temperature otherTemperature = obj as Temperature; if (otherTemperature !

IComparable-Schnittstelle (System)

= null) return this.temperatureF.CompareTo(otherTemperature.temperatureF); else throw new ArgumentException("Object is not a Temperature"); } public double Fahrenheit { get { return this.temperatureF; } set { this.temperatureF = value; } } public double Celsius { get { return (this.temperatureF - 32) * (5.0/9); } set { this.temperatureF = (value * 9.0/5) + 32; } } } public class CompareTemperatures { public static void Main() { ArrayList temperatures = new ArrayList(); // Initialize random number generator. Verwenden von Konstruktoren (C#) Public class Taxi { public bool isInitialized; public Taxi() { isInitialized = true; } } class TestTaxi { static void Main() { Taxi t = new Taxi(); Console.WriteLine(t.isInitialized); } } int i = new int(); Console.WriteLine(i); int i; Console.WriteLine(i); int a = 44; // Initialize the value type... int b; b = 33; // Or assign it before using it.

Verwenden von Konstruktoren (C#)

Console.WriteLine("{0}, {1}", a, b); public class Employee { public int salary; public Employee(int annualSalary) { salary = annualSalary; } public Employee(int weeklySalary, int numberOfWeeks) { salary = weeklySalary * numberOfWeeks; } } Employee e1 = new Employee(30000); Employee e2 = new Employee(500, 52); How to drag information from a DataGridView control. Introduction While doing some recent home-work, I needed to figure out how to implement drag-and-drop from a DataGridView control.

How to drag information from a DataGridView control

I had two main controls on the form: a ListBox that contained a list of categories, and a DataGridView control that contained a list of products associated with that category. To keep things simple, I wanted to be able to drag a product from the Grid to the ListBox to change a product's category. Starting the Drag-and-Drop The first thing I did was to attach an event handler to the DataGridView's MouseDown event. Void grdCampaigns_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { DataGridView.HitTestInfo info = grdCampaigns.HitTest(e.X, e.Y); if (info.RowIndex >= 0) { DataRowView view = (DataRowView) grdCampaigns.Rows[info.RowIndex].DataBoundItem; if (view !

The code tests for the right mouse Button. Preparing for the Drop All the above preparation is useless without having a target to drop the information in. Wegen OpenFileDialog BackgroundWorker als [STAThread] starten? DataSet.HasChanges-Methode (DataRowState) (System.Data) Public bool HasChanges( DataRowState rowStates ) private void UpdateDataSet(DataSet dataSet) { // Check for changes with the HasChanges method first. if(!

DataSet.HasChanges-Methode (DataRowState) (System.Data)

DataSet.HasChanges(DataRowState.Modified)) return; // Create temporary DataSet variable and // GetChanges for modified rows only. DataSet tempDataSet = dataSet.GetChanges(DataRowState.Modified); // Check the DataSet for errors. if(tempDataSet.HasErrors) { // Insert code to resolve errors. } // After fixing errors, update the data source with // the DataAdapter used to create the DataSet. adapter.Update(tempDataSet); } .NET Framework Unterstützt in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client Profile Unterstützt in: 4, 3.5 SP1 Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt) Referenz Weitere Ressourcen.

Using the BackgroundWorker Component in .NET 2 applications.