How to bind Dictionary to ListBox in WinForms

var choices = new Dictionary<string, string>(); choices[“A”] = “Arthur”; choices[“F”] = “Ford”; choices[“T”] = “Trillian”; choices[“Z”] = “Zaphod”; listBox1.DataSource = new BindingSource(choices, null); listBox1.DisplayMember = “Value”; listBox1.ValueMember = “Key”; (Shamelessly lifted from my own blog: Bind a ComboBox to a generic Dictionary.) This means you can use SelectedValue to get hold of the corresponding dictionary … Read more

Adding Text to DataGridView Row Header

private void dtgworkingdays_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { this.FillRecordNo(); } private void FillRecordNo() { for (int i = 0; i < this.dtworkingdays.Rows.Count; i++) { this.dtgworkingdays.Rows[i].HeaderCell.Value = (i + 1).ToString(); } } Also see Show row number in row header of a DataGridView.

How to draw a rounded rectangle in c#

public static GraphicsPath RoundedRect(Rectangle bounds, int radius) { int diameter = radius * 2; Size size = new Size(diameter, diameter); Rectangle arc = new Rectangle(bounds.Location, size); GraphicsPath path = new GraphicsPath(); if (radius == 0) { path.AddRectangle(bounds); return path; } // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = bounds.Right – … Read more