Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка Windows Forms > Создание DataGridViewComboBoxColumn


Автор: IAT 9.12.2011, 09:49
Доброго времени суток!
Подскажите пожалуйста, как правильно создавать DataGridViewComboBoxColumn???
Пробовал создавать как в нижеприведенном коде, коллекция которую принимает DataGridViewComboBoxColumn не отображается!
Код на C#:
Код

                List<Storage> allstorages = accessToDataArchive.GetAllStorages();
                List<string> currentTO = accessToDataArchive.GetCurrentTestObject();
                Storage_dgv.DataSource = allstorages;
                DataGridViewComboBoxColumn dgvComboB = new DataGridViewComboBoxColumn();
                dgvComboB.Name = "Object";
                dgvComboB.HeaderText = "Object";
                dgvComboB.DefaultCellStyle = Storage_dgv.DefaultCellStyle;
                dgvComboB.Items.AddRange(currentTO); 
                Storage_dgv.Columns.AddRange(dgvComboB);


Автор: VirusUZ 11.2.2012, 13:59
Код

using System.Windows.Forms;
namespace MainForm.Controls {
    public class MyGrid {
        public enum ColumnType {
            LABELCOLUMN = 0,
            CHECKBOX_COLUMN = 1,
            LINK_COLUMN = 2,
            COMBOBOX_COLUMN = 3
        }
        public static DataGridViewLinkColumn getColumnLink(string name, string header, string dataPropertyName) {
            DataGridViewLinkColumn link = new DataGridViewLinkColumn();
            link.Name = name;
            link.HeaderText = header;
            link.DataPropertyName = dataPropertyName;
            return link;
        }
        public static DataGridViewCheckBoxColumn getColumnCheckBox(string name, string header, string dataPropertyName) {
            DataGridViewCheckBoxColumn check = new DataGridViewCheckBoxColumn();
            check.Name = name;
            check.HeaderText = header;
            check.DataPropertyName = dataPropertyName;
            return check;
        }
        public static DataGridViewComboBoxColumn getColumnComboBox(string name, string header, string dataPropertyName) {
            DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
            combo.Name = name;
            combo.HeaderText = header;
            combo.DataPropertyName = dataPropertyName;
            return combo;
        }
        public static DataGridViewColumn getColumn(ColumnType columnType, string name, string headerText, string dataPropertyName) {
            DataGridViewColumn a = null;
            switch (columnType) {
                case ColumnType.CHECKBOX_COLUMN: {
                        a = getColumnCheckBox(name, headerText, dataPropertyName);
                    } break;
                case ColumnType.LINK_COLUMN: {
                        a = getColumnLink(name, headerText, dataPropertyName);
                    } break;
                case ColumnType.COMBOBOX_COLUMN: {
                        a = getColumnComboBox(name, headerText, dataPropertyName);
                    } break;
                default: {
                    a = new DataGridViewTextBoxColumn();
                    a.Name = name;
                    a.HeaderText = headerText;
                    a.DataPropertyName = dataPropertyName;
                    } break;
            }
            return a;
        }
        public static DataGridViewColumn getColumn(ColumnType columnType, string name, string headerText, string dataPropertyName, int width) {
            DataGridViewColumn a = getColumn(columnType, name, headerText, dataPropertyName);
            a.Width = width;
            a.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            return a;
        }
        public static DataGridViewColumn getColumn(string name, string headerText) {
            return getColumn(ColumnType.LABELCOLUMN, name, headerText, "");
        }
        public static DataGridViewColumn getColumn(string name, string headerText, string dataPropertyName) {
            return getColumn(ColumnType.LABELCOLUMN, name, headerText, dataPropertyName);
        }
        public static DataGridViewColumn getColumn(string name, string headerText, int width) {
            return getColumn(ColumnType.LABELCOLUMN, name, headerText, "", width);
        }
        public static DataGridViewColumn getColumn(string name, string headerText, string dataPropertyName, int width) {
            return getColumn(ColumnType.LABELCOLUMN, name, headerText, dataPropertyName, width);
        }
    }
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)