Skip to content

Instantly share code, notes, and snippets.

@gabrielgreen
Created June 28, 2012 20:10
Show Gist options
  • Save gabrielgreen/3013620 to your computer and use it in GitHub Desktop.
Save gabrielgreen/3013620 to your computer and use it in GitHub Desktop.
Quick way to display a grid of key/value pairs using LINQ to Objects and WinForms
if (EomAppCommon.Settings.DebugEomDatabase)
{
var form = new System.Windows.Forms.Form();
var grid = new System.Windows.Forms.DataGridView {
AutoGenerateColumns = true,
Dock = System.Windows.Forms.DockStyle.Fill,
DataSource =
(from c in new [] {
Tuple.Create("DADatabaseR1ConnectionString", this.DADatabaseR1ConnectionString),
Tuple.Create("StatsYear", this.StatsYear.ToString()),
Tuple.Create("StatsMonth", this.StatsMonth.ToString()),
Tuple.Create("StatsDaysInMonth", this.StatsDaysInMonth.ToString()),
Tuple.Create("PubReportSubjectLine", this.PubReportSubjectLine),
} select new {
Key = c.Item1,
Value = c.Item2,
}).ToList(),
AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill,
};
form.Controls.AddRange(new[] { grid, });
form.ShowDialog();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment