public static T GetSelectedRow <T>(DataTable DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) where T : DataRow { if (DataSource == null || DataSource.Rows.Count == 0) { return(null); } if (DataSource.Rows.Count == 1) { return(DataSource.Rows[0] as T); } using (var form = new SelectItemForm(DataSource, SelectedRow ?? DataSource.Rows[0], Columns)) if (FormServices.ShowFormDialog(form) == DialogResult.OK) { var drv = form.bindingSource.Current as DataRowView; if (drv != null) { return(drv.Row as T); } else { return(form.bindingSource.Current as T); } } else { return(null); } }
public static T GetSelectedRow <T>(string Text, string HeaderText, IEnumerable <T> DataSource, T SelectedRow, params SelectItemForm.ColumnDefinition[] Columns) { if (DataSource == null || DataSource.Count() == 0) { return(default(T)); } if (DataSource.Count() == 1) { return(DataSource.First()); } using (var form = new SelectItemForm(new SortableBindingList <T>(DataSource), SelectedRow == null ? DataSource.First() : SelectedRow, Columns)) { if (!string.IsNullOrWhiteSpace(Text)) { form.Text = Text; } if (!string.IsNullOrWhiteSpace(HeaderText)) { form.SetHeaderText(HeaderText); } if (FormServices.ShowFormDialog(form) == DialogResult.OK && form.bindingSource.Current is T) { return((T)form.bindingSource.Current); } else { return(default(T)); } } }
/// <summary> /// /// </summary> /// <param name="DataSource"></param> /// <param name="Text"></param> /// <param name="HeaderText"></param> /// <param name="Columns"></param> /// <returns></returns> public static void ShowData(object DataSource, string Text, string HeaderText, params SelectItemForm.ColumnDefinition[] Columns) { using (var form = new SelectItemForm(DataSource, null, Columns)) { if (!string.IsNullOrWhiteSpace(Text)) { form.Text = Text; } if (!string.IsNullOrWhiteSpace(HeaderText)) { form.SetHeaderText(HeaderText); } FormServices.ShowFormDialog(form); } }
internal static DataRow GetSelectedRow(object DataSource, string ValueMember = null, string DisplayMember = null, object SelectedValue = null, bool AutoGenerateColumns = false) { SelectItemForm.ColumnDefinition[] Columns = null; if (!AutoGenerateColumns && !string.IsNullOrWhiteSpace(ValueMember) && !string.IsNullOrWhiteSpace(DisplayMember)) { Columns = new SelectItemForm.ColumnDefinition[] { SelectItemForm.CreateColumnDefinition("Value", ValueMember), SelectItemForm.CreateColumnDefinition("Name", DisplayMember, FillWeight: 100), }; } using (var form = new SelectItemForm(DataSource, SelectedValue, Columns)) { try { var pos = form.bindingSource.Find(ValueMember, SelectedValue); if (pos >= 0) { form.bindingSource.Position = pos; } } catch { } if (FormServices.ShowFormDialog(form) == DialogResult.OK) { var drv = form.bindingSource.Current as DataRowView; if (drv != null) { return(drv.Row); } else { return(form.bindingSource.Current as DataRow); } } else { return(null); } } }