Example #1
0
        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));
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DataSource"></param>
        /// <param name="Text"></param>
        /// <param name="HeaderText"></param>
        /// <returns></returns>
        public static SelectItemForm CreateFormWithoutColumns(object DataSource, string Text = null, string HeaderText = null)
        {
            var form = new SelectItemForm(DataSource, null, new SelectItemForm.ColumnDefinition[] { null });

            if (!string.IsNullOrWhiteSpace(Text))
            {
                form.Text = Text;
            }
            if (!string.IsNullOrWhiteSpace(HeaderText))
            {
                form.SetHeaderText(HeaderText);
            }
            return(form);
        }
Example #3
0
 /// <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);
     }
 }