Skip to content

Static methods of SelectItemForm

Radu Martin edited this page Apr 14, 2017 · 18 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 select an item on the SelectItemForm. For showing items, please see the SelectItemForm page.

ColumnDefinition class

This class is used in all static methods of the SelectItemForm and describes columns on the dataGrid property.

public class ColumnDefinition
{
  public string HeaderText;
  public string DataPropertyName;
  public DataGridViewContentAlignment ContentAlignment;
  public float? FillWeight;
  public SqlDbType DataPropertyType;
}

There is a special static method on the SelectItemForm which helps in creating column:

public static ColumnDefinition 
    CreateColumnDefinition(
        string HeaderText, 
        string DataPropertyName,
        DataGridViewContentAlignment ContentAlignment = DataGridViewContentAlignment.NotSet, 
        float? FillWeight = null, 
        SqlDbType DataPropertyType = SqlDbType.NVarChar)

HeaderText is a text for column's header,
DataPropertyName is the name of the property in IEnumerable or ColumnName in the DataTable,
ContentAlignment describes how will cell's content align,
FillWeight represents the width of the column when it is in fill mode,
DataPropertyType - describes data type of column.

Choose an item from IEnumerable

There are several static methods for selecting an item from IEnumerable. The main of them is:

public static T GetSelectedRow<T>(
                    string Text, string HeaderText, 
                    IEnumerable<T> DataSource, 
                    T SelectedRow, 
                    params SelectItemForm.ColumnDefinition[] Columns)

Choose a DataRow from DataTable

The main static method for selecting DataRow from typed or untyped DataTable:

public static T GetSelectedRow<T>(
                    DataTable DataSource, 
                    T SelectedRow, 
                    params SelectItemForm.ColumnDefinition[] Columns) 
        where T : DataRow