Skip to content

SelectItemForm

Radu Martin edited this page Apr 14, 2017 · 46 revisions

SelectItemForm is a dialogue form which is using for select an item from lists such as IEnumerable or DataTable. Also, the SelectItemForm has ability to sort items by clicking on the column's headers and filtering items by criteria from TextBox control which exists on the dialogue.

This page describes how to show items on the SelectItemForm. For selecting items, please see the Static methods of SelectItemForm page.

Using SelectItemForm for showing data

The SelectItemForm can automatically detect properties or columns from DataSource:

class Person
{
  public string FirtName { get; set; }
  public string LastName { get; set; }
}

var persons = new List<Person>();
persons.Add(new Person() { FirtName = "Scott", LastName = "Fridder" });
persons.Add(new Person() { FirtName = "Elvin", LastName = "Kart" });
persons.Add(new Person() { FirtName = "Peruta", LastName = "Zambi" });
persons.Add(new Person() { FirtName = "Rokar", LastName = "Bansheer" });

SelectItemForm.ShowData(persons, "People");

SelectItemForm

Configure visualization on DataGridView

The big point of the SelectItemForm is on the dataGrid property which can be configured by DataGridView extenders.

IEnumerable

var items = new Dictionary<int, string>();
items.Add(1, "First value");
items.Add(2, "Second value");
items.Add(3, "More values...");

using (var form = SelectItemForm.CreateFormWithoutColumns(
                      items, "My values", "These values are mine"))
{
  form.dataGrid.AddTextColumn("key", "Key").SetNumberStyle();
  form.dataGrid.AddTextColumn("value", "Value").SetAutoSizeFillStyle(50);
  form.ShowDialog();
}

SelectItemForm

DataTable and DataColumns

var items = new DataTable();
items.Columns.AddRange(new DataColumn[] {
    new DataColumn("ID", typeof(byte)),
    new DataColumn("Group", typeof(string)),
    new DataColumn("Remarks", typeof(string))});
items.Columns[0].Unique = true;
items.Columns[2].AllowDBNull = true;
items.Rows.Add(0, "Default");
items.Rows.Add(1, "Regular", "Regular group");
items.Rows.Add(2, "RG+Bonus", "Regular group with bonuses");
items.Rows.Add(3, "RET");
items.Rows.Add(4, "BIN");

using (var form = SelectItemForm.CreateFormWithoutColumns(items, "Groups"))
{
  form.dataGrid.AddTextColumn(
        items.Columns[0].ColumnName, "ID").SetNumberStyle();
  form.dataGrid.AddTextColumn(
        items.Columns[1].ColumnName, "Group");
  form.dataGrid.AddTextColumn(
        items.Columns[2].ColumnName, "Remarks").SetAutoSizeFillStyle(50);
  form.ShowDialog();
}

SelectItemForm

Additional methods

The SelectItemForm provides two methods for showing the text on Header and Footer:

public void SetHeaderText(string Text)
public void SetFooterText(string Text)