Exemplo n.º 1
0
        private void dtgCompetition()
        {
            metroGrid2.EditMode = DataGridViewEditMode.EditOnEnter;
            //ComboBox 유형의 셀 만들고
            DataGridViewComboBoxColumn[] ComboBoxCell = new DataGridViewComboBoxColumn[mainFrm.selectCompetitionAndSimilarity.Where(c => c).Count() - 1];

            //DisplayStyle을 ComboBox로 설정
            for (int i = 0; i < ComboBoxCell.Count(); i++)
            {
                ComboBoxCell[i]      = new DataGridViewComboBoxColumn();
                ComboBoxCell[i].Name = mainFrm.SelectedCompetitionMenu[i];
                ComboBoxCell[i].Items.Add("열세");
                ComboBoxCell[i].Items.Add("유사");
                ComboBoxCell[i].Items.Add("우세");

                ComboBoxCell[i].DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                ComboBoxCell[i].FlatStyle    = FlatStyle.Flat;
            }
            textBox1.Size       = metroGrid2.Size;
            metroGrid2.Location = new Point(textBox1.Location.X, textBox1.Location.Y + textBox1.Size.Height + 1);
            metroGrid2.Rows.Clear();

            metroGrid2.RowHeadersVisible    = false;
            metroGrid2.ColumnHeadersVisible = true;
            metroGrid2.ColumnCount          = 2;

            metroGrid2.Columns[0].Name = "기 종";
            metroGrid2.Columns[1].Name = "단 가";

            for (int i = 0; i < Competition2.CompetitionWeapon.Length; i++)
            {
                metroGrid2.Rows.Add(Competition2.CompetitionWeapon[i]);
                metroGrid2.Rows[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                metroGrid2.Rows[i].Cells[0].Style.BackColor   = Color.FromArgb(222, 235, 247);
            }

            metroGrid2.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(32, 56, 100);
            metroGrid2.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            metroGrid2.ColumnHeadersDefaultCellStyle.Font      = new Font("나눔고딕", 9, FontStyle.Bold);

            DataGridViewColumn dataGridViewColumn = metroGrid2.Columns[0];

            dataGridViewColumn.HeaderCell.Style.BackColor = Color.FromArgb(91, 155, 213);
            dataGridViewColumn.HeaderCell.Style.ForeColor = Color.White;

            // 단가
            DataGridViewColumn dataGridViewColumn2 = metroGrid2.Columns[1];

            dataGridViewColumn2.HeaderCell.Style.BackColor = Color.FromArgb(255, 192, 0);
            dataGridViewColumn2.HeaderCell.Style.ForeColor = Color.Black;


            // 구분 색깔
            for (int i = 0; i < 1; i++)
            {
                metroGrid2.Rows[i].Cells[0].ReadOnly = true;
                metroGrid2.Rows[i].Cells[1].ReadOnly = true;
            }


            int count = 0;

            for (int i = 0; i < mainFrm.selectCompetitionAndSimilarity.Length; i++)
            {
                if (mainFrm.CompetitionData[0, i].ToString().IndexOf("Prices") != -1 ||
                    mainFrm.CompetitionData[0, i].ToString().IndexOf("단가") != -1 ||
                    mainFrm.CompetitionData[0, i].ToString().IndexOf("가격") != -1)
                {
                    continue;
                }

                if (mainFrm.selectCompetitionAndSimilarity[i] == true)
                {
                    metroGrid2.Columns.Add(ComboBoxCell[count]);
                    count++;
                }
            }

            #region 경쟁무기체계 DB에서 추가함

            // 경쟁무기체계를 추가함

            for (int j = 0; j < metroGrid2.RowCount; j++)
            {
                metroGrid2.Rows[j].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                metroGrid2.Rows[j].Cells[1].Style.BackColor   = Color.White;
                //    metroGrid2.Rows[j].Cells[1].Style.ForeColor = Color.White;

                metroGrid2.Rows[j].Cells[1].ReadOnly = true;
            }

            for (int i = 2; i < metroGrid2.ColumnCount; i++)
            {
                for (int j = 0; j < metroGrid2.RowCount; j++)
                {
                    metroGrid2.Rows[j].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    metroGrid2.Rows[j].Cells[i].Style.BackColor   = Color.White;
                }
            }
            #endregion
            // Design
            metroGrid2.DefaultCellStyle.BackColor = Color.White;

            this.metroGrid2.DefaultCellStyle.Font = new Font("나눔고딕", 9);
            for (int i = 0; i < metroGrid2.RowCount; i++)
            {
                metroGrid2.Rows[i].Cells[0].Style.WrapMode = DataGridViewTriState.False;
            }
            metroGrid2.Columns[0].Width        = 300;
            metroGrid2.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;

            for (int i = 1; i < metroGrid2.ColumnCount; i++)
            {
                metroGrid2.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
            foreach (DataGridViewColumn column in metroGrid2.Columns)
            {
                column.SortMode = DataGridViewColumnSortMode.NotSortable;
                column.DefaultCellStyle.Font = new Font("나눔고딕", 9);
            }

            for (int i = 2; i < metroGrid2.ColumnCount; i++)
            {
                for (int j = 0; j < metroGrid2.RowCount; j++)
                {
                    int WeaponIndex = mainFrm.CompetitionWeapon.IndexOf(metroGrid2.Rows[j].Cells[0].Value.ToString());
                    int SpecIndex   = Array.IndexOf(mainFrm.FullSpecCompetitionAndSimilarity, metroGrid2.Columns[i].Name.ToString());

                    metroGrid2.Rows[j].Cells[i].Value = mainFrm.CostEffectiveCompetitionAndSimilar[WeaponIndex, SpecIndex];
                }
            }
            //      metroGrid2.CurrentCell = null;
        }
Exemplo n.º 2
0
 public void FillComboDatagrid(DataGridViewComboBoxColumn dgvc)
 {
     mAsig.FillComboDatagridView(dgvc);
 }
Exemplo n.º 3
0
        private void InitTaskGrid()
        {
            this._taskGrid.AutoGenerateColumns     = false;
            this._taskGrid.AllowUserToAddRows      = false;
            this._taskGrid.MultiSelect             = false;
            this._taskGrid.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.Fill;
            this._taskGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            this._taskGrid.RowHeadersWidth         = c_gridRowHeadersWidth;
            if (_tasksHolder != null)
            {
                this._taskGrid.DataSource = Tasks;
            }
            this._taskGrid.CellClick                    += new DataGridViewCellEventHandler(_taskGrid_CellClick);
            this._taskGrid.CurrentCellChanged           += new EventHandler(_taskGrid_CurrentCellChanged);
            this._taskGrid.DataError                    += new DataGridViewDataErrorEventHandler(_taskGrid_DataError);
            this._taskGrid.CellFormatting               += new DataGridViewCellFormattingEventHandler(_taskGrid_CellFormatting);
            this._taskGrid.CellParsing                  += new DataGridViewCellParsingEventHandler(_taskGrid_CellParsing);
            this._taskGrid.CellPainting                 += new DataGridViewCellPaintingEventHandler(_taskGrid_CellPainting);
            this._taskGrid.RowsAdded                    += new DataGridViewRowsAddedEventHandler(_taskGrid_RowsAdded);
            this._taskGrid.RowsRemoved                  += new DataGridViewRowsRemovedEventHandler(_taskGrid_RowsRemoved);
            this._taskGrid.DataBindingComplete          += new DataGridViewBindingCompleteEventHandler(_taskGrid_DataBindingComplete);
            this._taskGrid.CurrentCellDirtyStateChanged += new EventHandler(_taskGrid_CurrentCellDirtyStateChanged);

            // file name:
            DataGridViewTextBoxColumn colFileName = new DataGridViewTextBoxColumn();

            colFileName.Name                      = "File Name";
            colFileName.DataPropertyName          = "FileName";
            colFileName.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            colFileName.Width                     = c_gridFileNameWidth;
            _taskGrid.Columns.Add(colFileName);
            _taskGridInfo.FileNameColIdx = colFileName.Index;

            // file selection ellipsis:
            DataGridViewButtonColumn colFileSelect = new DataGridViewButtonColumn();
            // using column template allows to set tooltip properly:
            DataGridViewButtonCell tpl = new DataGridViewButtonCell();

            tpl.ToolTipText = "Click to select file name";
            tpl.UseColumnTextForButtonValue = true;
            colFileSelect.CellTemplate      = tpl;
            colFileSelect.Text         = "\x2026"; // ellipsis
            colFileSelect.Width        = c_btnWidth;
            colFileSelect.MinimumWidth = c_btnWidth;
            colFileSelect.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            colFileSelect.Resizable    = DataGridViewTriState.False;
            colFileSelect.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            _taskGrid.Columns.Add(colFileSelect);
            _taskGridInfo.FileSelectColIdx = colFileSelect.Index;

            // report name:
            DataGridViewComboBoxColumn colReportName = new DataGridViewComboBoxColumn();

            colReportName.DataPropertyName          = "ReportName";
            colReportName.Name                      = "Report Name";
            colReportName.ValueType                 = typeof(string);
            colReportName.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            colReportName.Width                     = c_gridReportNameWidth;
            _taskGrid.Columns.Add(colReportName);
            _taskGridInfo.ReportNameColIdx = colReportName.Index;

            // task type:
            DataGridViewComboBoxColumn colTaskKind = new DataGridViewComboBoxColumn();

            colTaskKind.DataPropertyName          = "ReportKind";
            colTaskKind.Name                      = "Report Type";
            colTaskKind.DataSource                = c_taskKinds;
            colTaskKind.ValueType                 = typeof(ReportKind);
            colTaskKind.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            _taskGrid.Columns.Add(colTaskKind);
            _taskGridInfo.TaskKindColIdx = colTaskKind.Index;

            // task checked status:
            DataGridViewImageColumn colCheckedStatus = new DataGridViewImageColumn();

            colCheckedStatus.DataPropertyName          = "CheckedStatus";
            colCheckedStatus.Width                     = c_btnWidth;
            colCheckedStatus.MinimumWidth              = c_btnWidth;
            colCheckedStatus.AutoSizeMode              = DataGridViewAutoSizeColumnMode.None;
            colCheckedStatus.Resizable                 = DataGridViewTriState.False;
            colCheckedStatus.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            _taskGrid.Columns.Add(colCheckedStatus);
            _taskGridInfo.CheckedStatusColIdx = colCheckedStatus.Index;

            // task state:
            DataGridViewTextBoxColumn colReady = new DataGridViewTextBoxColumn();

            colReady.ReadOnly                  = true;
            colReady.Name                      = "Status";
            colReady.DataPropertyName          = "State";
            colReady.AutoSizeMode              = DataGridViewAutoSizeColumnMode.DisplayedCells;
            colReady.HeaderCell.Style.WrapMode = DataGridViewTriState.False;
            _taskGrid.Columns.Add(colReady);
            _taskGridInfo.ReadyColIdx = colReady.Index;
        }
Exemplo n.º 4
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (var _session = SoSession.Authenticate(Username, Password))
                {
                    DataGridViewComboBoxColumn rolesColumn = (DataGridViewComboBoxColumn)dtUsersList.Columns["Role"];
                    rolesColumn.DataSource    = roles.ToList();
                    rolesColumn.DisplayMember = "Name";

                    DataGridViewComboBoxColumn groupsColumn = (DataGridViewComboBoxColumn)dtUsersList.Columns["UserGroup"];
                    groupsColumn.DataSource    = groups.ToList();
                    groupsColumn.DisplayMember = "Value";
                    p = new FileParser(openFileDialog.FileName);

                    MessageBox.Show("File parsed, " + p.UserInfos.Count.ToString() + " users read\n");

                    foreach (ImportUserInfo ui in p.UserInfos)
                    {
                        ContactTableInfo          cti  = TablesInfo.GetContactTableInfo();
                        OwnerContactLinkTableInfo octi = TablesInfo.GetOwnerContactLinkTableInfo();
                        Select findOc = S.NewSelect("Find OC");

                        findOc.JoinRestriction.InnerJoin(cti.ContactId.Equal(octi.ContactId));

                        // if contact name contains a comma, assume that pre-comma is name and post-comma is department (db & file are set up that way)
                        if (ui.Company.Contains(","))
                        {
                            findOc.Restriction = cti.Name.Equal(S.Parameter(ui.Company.Split(',')[0].Trim())).
                                                 And(cti.Department.Equal(S.Parameter(ui.Company.Split(',')[1].Trim())));
                        }
                        else
                        {
                            findOc.Restriction = cti.Name.Equal(S.Parameter(ui.Company));
                        }

                        findOc.ReturnFields.Add(cti.ContactId);

                        int ocId = QueryExecutionHelper.ExecuteTypedScalar <int>(findOc);

                        if (ocId == 0)
                        {
                            //MessageBox.Show("Owner company " + ui.Company + "(referenced by " + ui.UID + ")  does not exist OR is not an Owner Company - setting to License Owner " + SoSystemInfo.GetCurrent().CompanyName);
                            ui.Company = SoSystemInfo.GetCurrent().CompanyName;
                            if (!_contacts.ContainsKey(SoSystemInfo.GetCurrent().CompanyName))
                            {
                                _contacts.Add(ui.Company, SoSystemInfo.GetCurrent().CompanyId);
                            }
                        }
                        else if (!_contacts.ContainsKey(ui.Company))
                        {
                            _contacts.Add(ui.Company, ocId);
                        }

                        if (!_roles.ContainsKey(ui.Role))
                        {
                            ui.Role = DefaultRole;
                        }
                        if (!_groups.ContainsKey(ui.Group))
                        {
                            ui.Group = DefaultGroup;
                        }
                    }
                    Dictionary <string, int> users = Importer.FindUsers();

                    dtUsersList.AutoGenerateColumns = false;
                    dtUsersList.Columns["FirstName"].DataPropertyName   = "FirstName";
                    dtUsersList.Columns["LastName"].DataPropertyName    = "LastName";
                    dtUsersList.Columns["FullName"].DataPropertyName    = "FullName";
                    dtUsersList.Columns["UserName"].DataPropertyName    = "UID";
                    dtUsersList.Columns["Email"].DataPropertyName       = "Email";
                    dtUsersList.Columns["Role"].DataPropertyName        = "Role";
                    dtUsersList.Columns["UserGroup"].DataPropertyName   = "Group";
                    dtUsersList.Columns["Company"].DataPropertyName     = "Company";
                    dtUsersList.Columns["AssociateId"].DataPropertyName = "AssociateId";
                    dtUsers = Importer.ConvertToDataTable <ImportUserInfo>(p.UserInfos);
                    dtUsersList.DataSource = dtUsers;
                    //dtUsersList.DataSource = p.UserInfos;
                    progressBar.Value = 0;
                    foreach (DataGridViewRow item in dtUsersList.Rows)
                    {
                        string username = item.Cells["UserName"].Value.ToString();
                        if (users.ContainsKey(username))
                        {
                            item.Cells["Status"].Value      = "Exists";
                            item.Cells["AssociateId"].Value = users[username];
                            string license = Importer.GetLicense(users[username], LookupList);
                            item.Cells["AssignedLicenses"].Value = license;
                        }
                        else
                        {
                            item.Cells["AssociateId"].Value      = DBNull.Value;
                            item.Cells["Status"].Value           = "New";
                            item.Cells["AssignedLicenses"].Value = "";
                        }
                    }
                }
                btnProcess.Enabled = true;
                progressBar.Value  = 0;
                txtSearch.Text     = "";
                lblSearch.Visible  = true;
                txtSearch.Visible  = true;
            }
        }
        public void SetEditable(bool bEditable)
        {
            m_bIsEditable = bEditable;
            if (m_bIsEditable)
            {
                // 设定标题栏,默认有个隐藏列
                this.Header = new string[]
                {
                    CS_Delete, CS_StationID, CS_StationName, CS_TimeCollected, CS_TotalRain, CS_DifferenceRain, CS_PeriodRain, CS_DayRain, CS_DataState, CS_TimeReceived, CS_ChannelType, CS_MsgType
                };
                //  this.HideColomns = new int[] { 10 };

                //开启编辑模式,设置可编辑列

                DataGridViewCheckBoxColumn deleteCol = new DataGridViewCheckBoxColumn();
                base.SetColumnEditStyle(0, deleteCol);

                //// 设置采集时间编辑列
                //CalendarColumn collectionCol = new CalendarColumn();
                //base.SetColumnEditStyle(3, collectionCol);

                // 累计雨量编辑列
                DataGridViewNumericUpDownColumn totalRain = new DataGridViewNumericUpDownColumn()
                {
                    Minimum       = 0,
                    Maximum       = 65537,
                    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/
                };
                base.SetColumnEditStyle(4, totalRain);

                //// 差值雨量编辑列
                //DataGridViewNumericUpDownColumn differneceRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(5, differneceRain);

                //// 时段雨量编辑列
                //DataGridViewNumericUpDownColumn periodRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(6, periodRain);

                //// 日雨量
                //DataGridViewNumericUpDownColumn dayRain = new DataGridViewNumericUpDownColumn()
                //{
                //    Minimum = 0,
                //    Maximum = 65537,
                //    DecimalPlaces = 1 /*好像是设置小数点后面的位数*/

                //};
                //base.SetColumnEditStyle(7, dayRain);

                // 数据状态,可编辑列
                DataGridViewComboBoxColumn dataStateCol = new DataGridViewComboBoxColumn();
                dataStateCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                dataStateCol.Items.AddRange(new object[] { CS_DataState_Normal, CS_DataState_AbNormal, CS_DataState_Warning });
                base.SetColumnEditStyle(8, dataStateCol);

                // 接收时间
                CalendarColumn recvTime = new CalendarColumn();
                base.SetColumnEditStyle(9, recvTime);


                // 通讯方式,不可编辑

                // 报文类型,不可编辑


                // 设置删除列的宽度
                this.Columns[0].Width = 40; //删除列宽度为20
                this.Columns[1].Width = 60;
                this.Columns[3].Width = 125;
                this.Columns[4].Width = 70;
                this.Columns[5].Width = 70;
                this.Columns[6].Width = 70;
                this.Columns[7].Width = 70;
                this.Columns[8].Width = 60;
                this.Columns[9].Width = 125; // 接收时间
            }
            else
            {
                this.Columns[0].Width = 60;
                this.Columns[2].Width = 125;
                this.Columns[3].Width = 70;
                this.Columns[4].Width = 70;
                this.Columns[5].Width = 70;
                this.Columns[6].Width = 70;
                this.Columns[7].Width = 60;
                this.Columns[8].Width = 125; // 接收时间
                //this.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                //this.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
Exemplo n.º 6
0
        private void createDinamicDataGridViewToOrders()
        {
            if (dgv != null)
            {
                return;
            }
            dgv = new DataGridView();

            dgv.CellContentClick    += Dgv_CellContentClick;
            dgv.DefaultValuesNeeded += Dgv_DefaultValuesNeeded;
            dgv.CellValueChanged    += Dgv_CellValueChanged;

            DataGridViewComboBoxColumn cbc = new DataGridViewComboBoxColumn();

            cbc.Name             = "pizzaName";
            cbc.HeaderText       = "      Pizza név    ";
            cbc.MaxDropDownItems = 5;
            cbc.DataSource       = repo.getPizzasName();
            cbc.AutoSizeMode     = DataGridViewAutoSizeColumnMode.AllCells;

            DataGridViewButtonColumn bcPlusz = new DataGridViewButtonColumn();

            bcPlusz.UseColumnTextForButtonValue = true;
            bcPlusz.HeaderText   = "Mennyiség növelés";
            bcPlusz.Name         = "bcPlusz";
            bcPlusz.Text         = "+";
            bcPlusz.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            DataGridViewButtonColumn bcMinusz = new DataGridViewButtonColumn();

            bcMinusz.UseColumnTextForButtonValue = true;
            bcMinusz.HeaderText   = "Mennyiség csökkentés";
            bcMinusz.Name         = "bcMinusz";
            bcMinusz.Text         = "-";
            bcMinusz.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            DataGridViewTextBoxColumn tbcMennyiseg = new DataGridViewTextBoxColumn();

            tbcMennyiseg.HeaderText   = "Mennyiség";
            tbcMennyiseg.Name         = "mennyiseg";
            tbcMennyiseg.ReadOnly     = true;
            tbcMennyiseg.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;

            DataGridViewTextBoxColumn tbcEgysegar = new DataGridViewTextBoxColumn();

            tbcEgysegar.HeaderText   = "Egységár";
            tbcEgysegar.Name         = "egysegar";
            tbcEgysegar.ReadOnly     = true;
            tbcEgysegar.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;

            dgv.Location = new Point(30, 60);
            dgv.Width    = 600;

            dgv.Columns.Add(cbc);
            dgv.Columns.Add(bcPlusz);
            dgv.Columns.Add(bcMinusz);
            dgv.Columns.Add(tbcMennyiseg);
            dgv.Columns.Add(tbcEgysegar);

            tabPageMegrendeles.Controls.Add(dgv);
        }
        private void LoadDataGridViewColumns()
        {
            try
            {
                DataGridViewTextBoxColumn tbDiffStatus = new DataGridViewTextBoxColumn();
                tbDiffStatus.Name       = "差異狀態";
                tbDiffStatus.Width      = 100;
                tbDiffStatus.HeaderText = "差異狀態";
                tbDiffStatus.ReadOnly   = true;

                DataGridViewComboBoxColumn cbProcStatus = new DataGridViewComboBoxColumn();
                cbProcStatus.Name       = "處理方式";
                cbProcStatus.Width      = 90;
                cbProcStatus.Width      = 120;
                cbProcStatus.HeaderText = "處理方式";

                DataTable dtPitems = new DataTable();
                dtPitems.Columns.Add("ITEM");
                dtPitems.Columns.Add("VALUE");

                List <string> items = new List <string>();
                items.Add("更新");
                items.Add("略過");
                items.Add("刪除");
                items.Add("新增");


                foreach (string str in items)
                {
                    DataRow dr = dtPitems.NewRow();
                    dr["ITEM"]  = str;
                    dr["VALUE"] = str;
                    dtPitems.Rows.Add(dr);
                }

                cbProcStatus.DataSource    = dtPitems;
                cbProcStatus.DisplayMember = "ITEM";
                cbProcStatus.ValueMember   = "VALUE";


                DataGridViewTextBoxColumn tbDomain = new DataGridViewTextBoxColumn();
                tbDomain.Name       = "領域";
                tbDomain.Width      = 70;
                tbDomain.HeaderText = "領域";
                tbDomain.ReadOnly   = true;

                DataGridViewTextBoxColumn tbScoreType = new DataGridViewTextBoxColumn();
                tbScoreType.Name       = "分項類別";
                tbScoreType.Width      = 90;
                tbScoreType.HeaderText = "分項類別";
                tbScoreType.ReadOnly   = true;

                DataGridViewTextBoxColumn tbSubjectName = new DataGridViewTextBoxColumn();
                tbSubjectName.Name       = "科目名稱";
                tbSubjectName.Width      = 150;
                tbSubjectName.HeaderText = "科目名稱";
                tbSubjectName.ReadOnly   = true;

                DataGridViewTextBoxColumn tbRequiredBy = new DataGridViewTextBoxColumn();
                tbRequiredBy.Name       = "校訂部定";
                tbRequiredBy.Width      = 90;
                tbRequiredBy.HeaderText = "校訂部定";
                tbRequiredBy.ReadOnly   = true;

                DataGridViewTextBoxColumn tbIsRequired = new DataGridViewTextBoxColumn();
                tbIsRequired.Name       = "必選修";
                tbIsRequired.Width      = 90;
                tbIsRequired.HeaderText = "必選修";
                tbIsRequired.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS11 = new DataGridViewTextBoxColumn();
                tbGS11.Name       = "1上";
                tbGS11.Width      = 60;
                tbGS11.HeaderText = "1上";
                tbGS11.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS12 = new DataGridViewTextBoxColumn();
                tbGS12.Name       = "1下";
                tbGS12.Width      = 60;
                tbGS12.HeaderText = "1下";
                tbGS12.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS21 = new DataGridViewTextBoxColumn();
                tbGS21.Name       = "2上";
                tbGS21.Width      = 60;
                tbGS21.HeaderText = "2上";
                tbGS21.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS22 = new DataGridViewTextBoxColumn();
                tbGS22.Name       = "2下";
                tbGS22.Width      = 60;
                tbGS22.HeaderText = "2下";
                tbGS22.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS31 = new DataGridViewTextBoxColumn();
                tbGS31.Name       = "3上";
                tbGS31.Width      = 60;
                tbGS31.HeaderText = "3上";
                tbGS31.ReadOnly   = true;

                DataGridViewTextBoxColumn tbGS32 = new DataGridViewTextBoxColumn();
                tbGS32.Name       = "3下";
                tbGS32.Width      = 60;
                tbGS32.HeaderText = "3下";
                tbGS32.ReadOnly   = true;

                DataGridViewTextBoxColumn tbOpenStatus = new DataGridViewTextBoxColumn();
                tbOpenStatus.Name       = "開課方式";
                tbOpenStatus.Width      = 90;
                tbOpenStatus.HeaderText = "開課方式";
                tbOpenStatus.ReadOnly   = true;

                DataGridViewTextBoxColumn tbCourseCode = new DataGridViewTextBoxColumn();
                tbCourseCode.Name       = "課程代碼";
                tbCourseCode.Width      = 300;
                tbCourseCode.HeaderText = "課程代碼";
                tbCourseCode.ReadOnly   = true;

                dgData.Columns.Add(tbDiffStatus);
                dgData.Columns.Add(cbProcStatus);
                dgData.Columns.Add(tbDomain);
                dgData.Columns.Add(tbScoreType);
                dgData.Columns.Add(tbSubjectName);
                dgData.Columns.Add(tbRequiredBy);
                dgData.Columns.Add(tbIsRequired);
                dgData.Columns.Add(tbGS11);
                dgData.Columns.Add(tbGS12);
                dgData.Columns.Add(tbGS21);
                dgData.Columns.Add(tbGS22);
                dgData.Columns.Add(tbGS31);
                dgData.Columns.Add(tbGS32);
                dgData.Columns.Add(tbOpenStatus);
                dgData.Columns.Add(tbCourseCode);

                //// 因為自動排序有些問題,先將關閉
                //foreach(DataGridViewColumn col in dgData.Columns )
                //{
                //    col.SortMode = DataGridViewColumnSortMode.NotSortable;
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 8
0
 public static void CarregaComboEnum <T>(ref DataGridViewComboBoxColumn combo, bool todos)
 {
     combo.DataSource    = TrataEnum.Listar(typeof(T), todos);
     combo.DisplayMember = "Value";
     combo.ValueMember   = "Key";
 }
Exemplo n.º 9
0
        public override void Execute(object cmdParams)
        {
            if (!MinoApi.LicenseCheck.LicenceCheck())// 20180427
            {
                return;
            }

            //get the root of physical//all physical
            TxPhysicalRoot physRoot = TxApplication.ActiveDocument.PhysicalRoot;
            //need filter.robot
            ITxTypeFilter objFilter = new TxTypeFilter(typeof(TxRobot));
            //return all descendants by filter
            TxObjectList objst = physRoot.GetAllDescendants(objFilter);

            //
            TxApplication.ActiveUndoManager.StartTransaction();

            MinoApi.MinoCEEForm rz = new MinoApi.MinoCEEForm();
            //
            rz.Robots = new TxRobot[objst.Count];

            if (objst.Count > 0)
            {
                TxRobot tr = objst[0] as TxRobot;
                if (tr.Controller.Name == "Fanuc-Rj")
                {
                    rz.radioButton2.Checked = true;
                }
                else
                {
                    rz.radioButton1.Checked = true;
                }
            }

            List <TxRobot> Roblist = new List <TxRobot>();

            foreach (TxRobot robot in objst)
            {
                Roblist.Add(robot);
            }
            Roblist = Roblist.OrderBy(s => s.Name).ToList();

            int c = objst.Count, i = 0;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle1.Alignment             = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            dataGridViewCellStyle1.Font                  = new System.Drawing.Font("宋体", 11F);
            rz.dataGridView3.Columns[0].HeaderCell.Style = dataGridViewCellStyle1;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Menu;
            DataGridViewComboBoxColumn col = rz.dataGridView2.Columns[0] as DataGridViewComboBoxColumn;

            foreach (TxRobot robot in Roblist)
            {
                rz.Robots[i] = robot;
                DataGridViewTextBoxColumn dc = new System.Windows.Forms.DataGridViewTextBoxColumn();
                dc.HeaderText       = robot.Name;
                dc.Name             = "Column" + i + 1;
                dc.HeaderCell.Style = dataGridViewCellStyle1;
                dc.DefaultCellStyle = dataGridViewCellStyle1;
                dc.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;

                rz.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                    dc
                });

                rz.dataGridView3.Rows.Add();
                rz.dataGridView3.Rows[i].Cells[0].Value = robot.Name;
                rz.dataGridView1.Rows.Add();
                rz.dataGridView1.Rows[i].Cells[i].Style = dataGridViewCellStyle2;

                DataGridViewTextBoxColumn dc1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
                dc1.HeaderText       = robot.Name;
                dc1.Name             = "Column" + i + 1;
                dc1.HeaderCell.Style = dataGridViewCellStyle1;
                dc1.DefaultCellStyle = dataGridViewCellStyle1;
                dc1.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
                rz.dataGridView8.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                    dc1
                });
                col.Items.Add(robot.Name);
                i = i + 1;
            }

            TxApplication.ActiveUndoManager.EndTransaction();
            rz.dataGridView8.Rows.Add();
            rz.Show();
        }
Exemplo n.º 10
0
        private DataGridView GetDGV(InventoryPouch pouch)
        {
            // Add DataGrid
            DataGridView dgv = new DataGridView
            {
                Dock = DockStyle.Fill,
                Text = pouch.Type.ToString(),
                Name = DGVPrefix + pouch.Type,

                AllowUserToAddRows       = false,
                AllowUserToDeleteRows    = false,
                AllowUserToResizeRows    = false,
                AllowUserToResizeColumns = false,
                RowHeadersVisible        = false,
                //ColumnHeadersVisible = false,
                MultiSelect     = false,
                ShowEditingIcon = false,

                EditMode = DataGridViewEditMode.EditOnEnter,
                ColumnHeadersBorderStyle    = DataGridViewHeaderBorderStyle.Single,
                ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                SelectionMode   = DataGridViewSelectionMode.CellSelect,
                CellBorderStyle = DataGridViewCellBorderStyle.None,
            };

            int c = 0;
            DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
            {
                HeaderText   = "Item",
                DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                DisplayIndex = c++,
                Width        = 135,
                FlatStyle    = FlatStyle.Flat
            };
            DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();

            {
                dgvIndex.HeaderText   = "Count";
                dgvIndex.DisplayIndex = c++;
                dgvIndex.Width        = 45;
                dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                if (!Main.HaX)
                {
                    ((DataGridViewTextBoxColumn)dgvIndex).MaxInputLength = (int)(Math.Log10(Math.Max(1, pouch.MaxCount)) + 1);
                }
            }

            dgv.Columns.Add(dgvItemVal);
            dgv.Columns.Add(dgvIndex);

            if (HasFreeSpace)
            {
                DataGridViewCheckBoxColumn dgvFree = new DataGridViewCheckBoxColumn
                {
                    HeaderText   = "Free",
                    DisplayIndex = c++,
                    Width        = 40,
                    FlatStyle    = FlatStyle.Flat
                };
                dgv.Columns.Add(dgvFree);
            }
            if (HasNew)
            {
                DataGridViewCheckBoxColumn dgvNew = new DataGridViewCheckBoxColumn
                {
                    HeaderText   = "NEW",
                    DisplayIndex = c++,
                    Width        = 40,
                    FlatStyle    = FlatStyle.Flat
                };
                dgv.Columns.Add(dgvNew);
            }

            var itemcount = pouch.Items.Length;

            string[] itemarr = Main.HaX ? (string[])itemlist.Clone() : GetItems(pouch.LegalItems);

            var combo = dgv.Columns[0] as DataGridViewComboBoxColumn;

            foreach (string t in itemarr)
            {
                combo.Items.Add(t); // add only the Item Names
            }
            dgv.Rows.Add(itemcount > 0 ? itemcount : itemarr.Length);
            dgv.CancelEdit();

            return(dgv);
        }
Exemplo n.º 11
0
        [NUnit.Framework.Category("NotWorking")]                // DGVComboBox not implemented
        public void AddRow_Changes()
        {
            using (DataGridView dgv = new DataGridView()) {
                DataGridViewColumn col  = new DataGridViewComboBoxColumn();
                DataGridViewRow    row  = new DataGridViewRow();
                DataGridViewCell   cell = new DataGridViewComboBoxCell();

                Assert.IsNotNull(row.AccessibilityObject, "#A row.AccessibilityObject");
                Assert.IsNotNull(row.Cells, "#A row.Cells");
                Assert.IsNull(row.ContextMenuStrip, "#A row.ContextMenuStrip");
                Assert.IsNull(row.DataBoundItem, "#A row.DataBoundItem");
                Assert.IsNull(row.DataGridView, "#A row.DataGridView");
                Assert.IsNotNull(row.DefaultCellStyle, "#A row.DefaultCellStyle");
                Assert.IsNotNull(row.DefaultHeaderCellType, "#A row.DefaultHeaderCellType");
                Assert.AreEqual(false, row.Displayed, "#A row.Displayed");
                Assert.AreEqual(0, row.DividerHeight, "#A row.DividerHeight");
                Assert.AreEqual(@"", row.ErrorText, "#A row.ErrorText");
                Assert.AreEqual(false, row.Frozen, "#A row.Frozen");
                Assert.AreEqual(true, row.HasDefaultCellStyle, "#A row.HasDefaultCellStyle");
                Assert.IsNotNull(row.HeaderCell, "#A row.HeaderCell");
                // DPI Dependent? // Assert.AreEqual (22, row.Height, "#A row.Height");
                Assert.AreEqual(-1, row.Index, "#A row.Index");
                try {
                    object zxf = row.InheritedStyle;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A row.InheritedStyle");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#A row.InheritedStyle");
                }
                Assert.AreEqual(false, row.IsNewRow, "#A row.IsNewRow");
                Assert.AreEqual(3, row.MinimumHeight, "#A row.MinimumHeight");
                Assert.AreEqual(false, row.ReadOnly, "#A row.ReadOnly");
                Assert.AreEqual(DataGridViewTriState.NotSet, row.Resizable, "#A row.Resizable");
                Assert.AreEqual(false, row.Selected, "#A row.Selected");
                Assert.AreEqual(DataGridViewElementStates.Visible, row.State, "#A row.State");
                Assert.IsNull(row.Tag, "#A row.Tag");
                Assert.AreEqual(true, row.Visible, "#A row.Visible");

                row.Cells.Add(cell);

                Assert.IsNotNull(row.AccessibilityObject, "#B row.AccessibilityObject");
                Assert.IsNotNull(row.Cells, "#B row.Cells");
                Assert.IsNull(row.ContextMenuStrip, "#B row.ContextMenuStrip");
                Assert.IsNull(row.DataBoundItem, "#B row.DataBoundItem");
                Assert.IsNull(row.DataGridView, "#B row.DataGridView");
                Assert.IsNotNull(row.DefaultCellStyle, "#B row.DefaultCellStyle");
                Assert.IsNotNull(row.DefaultHeaderCellType, "#B row.DefaultHeaderCellType");
                Assert.AreEqual(false, row.Displayed, "#B row.Displayed");
                Assert.AreEqual(0, row.DividerHeight, "#B row.DividerHeight");
                Assert.AreEqual(@"", row.ErrorText, "#B row.ErrorText");
                Assert.AreEqual(false, row.Frozen, "#B row.Frozen");
                Assert.AreEqual(true, row.HasDefaultCellStyle, "#B row.HasDefaultCellStyle");
                Assert.IsNotNull(row.HeaderCell, "#B row.HeaderCell");
                // DPI Dependent? // Assert.AreEqual (22, row.Height, "#B row.Height");
                Assert.AreEqual(-1, row.Index, "#B row.Index");
                try {
                    object zxf = row.InheritedStyle;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B row.InheritedStyle");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#B row.InheritedStyle");
                }
                Assert.AreEqual(false, row.IsNewRow, "#B row.IsNewRow");
                Assert.AreEqual(3, row.MinimumHeight, "#B row.MinimumHeight");
                Assert.AreEqual(false, row.ReadOnly, "#B row.ReadOnly");
                Assert.AreEqual(DataGridViewTriState.NotSet, row.Resizable, "#B row.Resizable");
                Assert.AreEqual(false, row.Selected, "#B row.Selected");
                Assert.AreEqual(DataGridViewElementStates.Visible, row.State, "#B row.State");
                Assert.IsNull(row.Tag, "#B row.Tag");
                Assert.AreEqual(true, row.Visible, "#B row.Visible");

                dgv.Columns.Add(col);

                Assert.IsNotNull(row.AccessibilityObject, "#C row.AccessibilityObject");
                Assert.IsNotNull(row.Cells, "#C row.Cells");
                Assert.IsNull(row.ContextMenuStrip, "#C row.ContextMenuStrip");
                Assert.IsNull(row.DataBoundItem, "#C row.DataBoundItem");
                Assert.IsNull(row.DataGridView, "#C row.DataGridView");
                Assert.IsNotNull(row.DefaultCellStyle, "#C row.DefaultCellStyle");
                Assert.IsNotNull(row.DefaultHeaderCellType, "#C row.DefaultHeaderCellType");
                Assert.AreEqual(false, row.Displayed, "#C row.Displayed");
                Assert.AreEqual(0, row.DividerHeight, "#C row.DividerHeight");
                Assert.AreEqual(@"", row.ErrorText, "#C row.ErrorText");
                Assert.AreEqual(false, row.Frozen, "#C row.Frozen");
                Assert.AreEqual(true, row.HasDefaultCellStyle, "#C row.HasDefaultCellStyle");
                Assert.IsNotNull(row.HeaderCell, "#C row.HeaderCell");
                // DPI Dependent? // Assert.AreEqual (22, row.Height, "#C row.Height");
                Assert.AreEqual(-1, row.Index, "#C row.Index");
                try {
                    object zxf = row.InheritedStyle;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C row.InheritedStyle");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#C row.InheritedStyle");
                }
                Assert.AreEqual(false, row.IsNewRow, "#C row.IsNewRow");
                Assert.AreEqual(3, row.MinimumHeight, "#C row.MinimumHeight");
                Assert.AreEqual(false, row.ReadOnly, "#C row.ReadOnly");
                Assert.AreEqual(DataGridViewTriState.NotSet, row.Resizable, "#C row.Resizable");
                Assert.AreEqual(false, row.Selected, "#C row.Selected");
                Assert.AreEqual(DataGridViewElementStates.Visible, row.State, "#C row.State");
                Assert.IsNull(row.Tag, "#C row.Tag");
                Assert.AreEqual(true, row.Visible, "#C row.Visible");

                dgv.Rows.Add(row);

                Assert.IsNotNull(row.AccessibilityObject, "#D row.AccessibilityObject");
                Assert.IsNotNull(row.Cells, "#D row.Cells");
                try {
                    object zxf = row.ContextMenuStrip;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ContextMenuStrip");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Operation cannot be performed on a shared row.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.ContextMenuStrip");
                }
                Assert.IsNull(row.DataBoundItem, "#D row.DataBoundItem");
                Assert.IsNotNull(row.DataGridView, "#D row.DataGridView");
                Assert.IsNotNull(row.DefaultCellStyle, "#D row.DefaultCellStyle");
                Assert.IsNotNull(row.DefaultHeaderCellType, "#D row.DefaultHeaderCellType");
                try {
                    object zxf = row.Displayed;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Displayed");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the Displayed property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.Displayed");
                }
                Assert.AreEqual(0, row.DividerHeight, "#D row.DividerHeight");
                try {
                    object zxf = row.ErrorText;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ErrorText");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Operation cannot be performed on a shared row.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.ErrorText");
                }
                try {
                    object zxf = row.Frozen;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Frozen");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the Frozen property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.Frozen");
                }
                Assert.AreEqual(true, row.HasDefaultCellStyle, "#D row.HasDefaultCellStyle");
                Assert.IsNotNull(row.HeaderCell, "#D row.HeaderCell");
                // DPI Dependent? // Assert.AreEqual (22, row.Height, "#D row.Height");
                Assert.AreEqual(-1, row.Index, "#D row.Index");
                try {
                    object zxf = row.InheritedStyle;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.InheritedStyle");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.InheritedStyle");
                }
                Assert.AreEqual(false, row.IsNewRow, "#D row.IsNewRow");
                Assert.AreEqual(3, row.MinimumHeight, "#D row.MinimumHeight");
                try {
                    object zxf = row.ReadOnly;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ReadOnly");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the ReadOnly property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.ReadOnly");
                }
                try {
                    object zxf = row.Resizable;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Resizable");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the Resizable property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.Resizable");
                }
                try {
                    object zxf = row.Selected;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Selected");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the Selected property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.Selected");
                }
                try {
                    object zxf = row.State;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.State");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the State property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.State");
                }
                Assert.IsNull(row.Tag, "#D row.Tag");
                try {
                    object zxf = row.Visible;
                    TestHelper.RemoveWarning(zxf);
                    Assert.Fail("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Visible");
                } catch (InvalidOperationException ex) {
                    Assert.AreEqual(@"Getting the Visible property of a shared row is not a valid operation.", ex.Message);
                } catch (Exception ex) {
                    Assert.Fail("Expected 'System.InvalidOperationException', got '" + ex.GetType().FullName + "'.", "#D row.Visible");
                }
            }
        }
Exemplo n.º 12
0
        public void CreateTable(int type)
        {
            table = new DataTable();
            switch (type)
            {
            case 1:
                string sqlselect = string.Empty;
                if (lista_modifica.SelectedItem.ToString() == lista_modifica.Items[0].ToString())
                {
                    sqlselect = string.Format("SELECT IDProfesor,Nume,Prenume FROM Materii;");
                    table     = MyData.readTable(sqlselect);
                    string sql = string.Format("SELECT ID_Materie,Nume_Materie FROM TabelMaterii;");
                    table_materii = MyData.readTable(sql);
                    table.Columns.Add("Materie");
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        string materie_sql = string.Format("SELECT IDMaterie FROM Materii WHERE IDProfesor={0};", table.Rows[i][0]);
                        int    materie_id  = MyData.selectData(materie_sql, "IDMaterie");
                        for (int j = 0; j < table_materii.Rows.Count; j++)
                        {
                            if (Convert.ToInt32(table_materii.Rows[j][0]) == materie_id)
                            {
                                table.Rows[i]["Materie"] = table_materii.Rows[j][1];
                            }
                        }
                    }
                }
                else
                {
                    sqlselect = string.Format("SELECT ID_Student,Nume,Prenume FROM Grades;");
                    table     = MyData.readTable(sqlselect);
                }
                date_dgv.Columns.Clear();
                date_dgv.DataSource = table;
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                btn.HeaderText = "Sterge " + lista_modifica.SelectedItem.ToString();
                btn.Name       = "delete_btn";
                btn.Text       = "Sterge";
                btn.ValueType  = typeof(Button);
                btn.UseColumnTextForButtonValue = true;
                date_dgv.Columns.Add(btn);
                break;

            case 2:
                string sqlmodifica = string.Empty;
                if (lista_modifica.SelectedItem.ToString() == lista_modifica.Items[0].ToString())
                {
                    sqlmodifica = string.Format("SELECT Materii.IDProfesor,Materii.Nume,Materii.Prenume,TabelMaterii.Nume_Materie,Profesori.Nick,Profesori.Pass FROM Materii,TabelMaterii,Profesori WHERE Profesori.IDMaterie=TabelMaterii.ID_Materie AND Profesori.ID_Prof=Materii.IDProfesor;");
                    table       = MyData.readTable(sqlmodifica);
                    modifica_dgv.Columns.Clear();
                    modifica_dgv.DataSource = table;
                    //Remodelate coloana 4 intr-o lista dropdown
                    DataGridViewComboBoxColumn list_materii = new DataGridViewComboBoxColumn();
                    list_materii.HeaderText = "Materie";
                    list_materii.Name       = "lst_materii";
                    DataTable dt  = getMaterii();
                    object[]  obj = new object[dt.Rows.Count];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        obj[i] = dt.Rows[i]["Nume_Materie"];
                    }
                    list_materii.Items.AddRange(obj);
                    modifica_dgv.Columns.RemoveAt(3);
                    modifica_dgv.Columns.Add(list_materii);
                    for (int i = 0; i < modifica_dgv.RowCount; i++)
                    {
                        modifica_dgv["lst_materii", i].Value = table.Rows[i]["Nume_Materie"];
                    }
                    //buton cu ce teste a adaugat
                    DataGridViewButtonColumn ts = new DataGridViewButtonColumn();
                    ts.Name       = "teste_btn";
                    ts.HeaderText = "Teste adaugate";
                    ts.Text       = "Editeaza";
                    ts.UseColumnTextForButtonValue = true;
                    ts.ValueType = typeof(Button);
                    modifica_dgv.Columns.Add(ts);
                    modifica_dgv.Columns["IDProfesor"].ReadOnly = true;
                }
                else
                {
                    sqlmodifica = string.Format("SELECT Grades.ID_Student,Grades.Nume,Grades.Prenume,Studenti.Nick,Studenti.Parola,Grades.Materii_inscris FROM Studenti,Grades WHERE Grades.ID_Student=Studenti.ID_Student;");
                    table       = MyData.readTable(sqlmodifica);
                    modifica_dgv.Columns.Clear();
                    modifica_dgv.DataSource = table;
                    modifica_dgv.Columns["Materii_inscris"].Name = "ID_Materii";
                    //buton teste windows
                    DataGridViewButtonColumn button = new DataGridViewButtonColumn();
                    button.Name       = "teste_btn";
                    button.HeaderText = "Teste";
                    button.Text       = "Vezi teste";
                    button.ValueType  = typeof(Button);
                    button.UseColumnTextForButtonValue = true;
                    modifica_dgv.Columns.Add(button);
                    modifica_dgv.Columns["ID_Student"].ReadOnly = true;
                }
                break;
            }
        }
Exemplo n.º 13
0
        public static void InitializeComboBox(String dataAdapterapterString, String displayMem,
                                              String valueMem, object[] defaultDataRowParams, ref DataGridViewComboBoxColumn combBx)
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(@dataAdapterapterString, SqlC.c);
            DataTable      dataTable   = new DataTable();

            dataAdapter.Fill(dataTable);

            DataRow defaultDataRow = dataTable.NewRow();

            defaultDataRow.ItemArray = defaultDataRowParams;
            dataTable.Rows.InsertAt(defaultDataRow, 0);

            double symbolScale   = 6.45;
            int    maxItemLenght = combBx.Width;

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                if (maxItemLenght < ((int)(dataTable.Rows[i][displayMem].ToString().Length *symbolScale)))
                {
                    maxItemLenght = ((int)(dataTable.Rows[i][displayMem].ToString().Length *symbolScale));
                }
            }
            combBx.DropDownWidth = maxItemLenght;

            combBx.DataSource    = dataTable;
            combBx.DisplayMember = displayMem;
            combBx.ValueMember   = valueMem;
        }
Exemplo n.º 14
0
        protected void AddColumn(DataGridView grid, int colType, string Field, bool IsHide, bool HasSort,
                                 byte CenterFlag, int colWidth)
        {
            DataGridViewTextBoxColumn  colText;
            DataGridViewCheckBoxColumn colCheck;
            DataGridViewComboBoxColumn colCombo;

            switch (colType)
            {
            case 0:
                colText = new DataGridViewTextBoxColumn();
                colText.DataPropertyName = Field;
                colText.Visible          = !IsHide;
                if (!HasSort)
                {
                    colText.SortMode = DataGridViewColumnSortMode.NotSortable;
                }
                colText.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                if (CenterFlag == 1)
                {
                    colText.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
                else if (CenterFlag == 2)
                {
                    colText.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                }
                if (colWidth > 0)
                {
                    colText.Width = colWidth;
                }
                else
                {
                    colText.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                grid.Columns.Add(colText);
                break;

            case 1:
                colCheck = new DataGridViewCheckBoxColumn();
                colCheck.DataPropertyName           = Field;
                colCheck.Visible                    = !IsHide;
                colCheck.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                if (CenterFlag == 1)
                {
                    colCheck.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
                else if (CenterFlag == 2)
                {
                    colCheck.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                }
                if (colWidth > 0)
                {
                    colCheck.Width = colWidth;
                }
                else
                {
                    colCheck.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                grid.Columns.Add(colCheck);
                break;

            case 2:
                colCombo = new DataGridViewComboBoxColumn();
                colCombo.DataPropertyName           = Field;
                colCombo.Visible                    = !IsHide;
                colCombo.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                if (CenterFlag == 1)
                {
                    colCombo.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
                else if (CenterFlag == 2)
                {
                    colCombo.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                }
                if (colWidth > 0)
                {
                    colCombo.Width = colWidth;
                }
                else
                {
                    colCombo.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                colCombo.DisplayStyleForCurrentCellOnly = true;
                grid.Columns.Add(colCombo);
                break;
            }
        }
Exemplo n.º 15
0
 public void AddItemsInComboBox(DataGridViewComboBoxColumn comboboxColumn)
 {
     //DB_Part_OS2Entities db = new DB_Part_OS2Entities();
     //comboboxColumn.Items.AddRange((from d in db.tbl_Modul_Name select d.Short_Name_Modul_Name).ToArray());
 }
Exemplo n.º 16
0
        public static void AddColumns(TSDataGridView dgv, TSGrid hsGrid)
        {
            if (dgv == null)
            {
                throw new ArgumentNullException("dgv");
            }
            if (hsGrid == null)
            {
                throw new ArgumentNullException("hsGrid");
            }

            List <TSGridColumn> columns = hsGrid.Columns;

            DataGridViewColumn[] gridColumns = new DataGridViewColumn[columns.Count];
            for (int i = 0, count = columns.Count; i < count; i++)
            {
                TSGridColumn col = columns[i];

                DataGridViewColumn column = null;
                switch (col.ColumnType)
                {
                case TSGridColumnType.CheckBox:
                {
                    column = new DataGridViewCheckBoxColumn();
                }
                break;

                case TSGridColumnType.Image:
                {
                    column     = new DataGridViewImageColumn();
                    column.Tag = col.DefaultValue;
                }
                break;

                case TSGridColumnType.Text:
                {
                    column = new DataGridViewTextBoxColumn();
                }
                break;

                case TSGridColumnType.ComboBox:
                {
                    column = new DataGridViewComboBoxColumn();
                }
                break;

                case TSGridColumnType.NumericUpDown:
                {
                    var numericCell = new DataGridViewNumericUpDownColumn();
                    numericCell.Minimum   = 0;
                    numericCell.Increment = 1;
                    numericCell.Maximum   = 100;

                    column = numericCell;
                }
                break;

                default:
                {
                    column = new DataGridViewTextBoxColumn();
                }
                break;
                }

                if (col.ValueType == DataValueType.Float)
                {
                    column.DefaultCellStyle.Format = "##0.000";
                }

                column.HeaderText = col.Text;
                column.Name       = col.Name;
                column.Width      = col.Width;
                column.ReadOnly   = (col.ReadOnly != 0) ? true : false;
                column.Visible    = (col.Visible != 0) ? true : false;
                gridColumns[i]    = column;

                if (hsGrid.Background == 1 && column.ReadOnly)
                {
                    column.DefaultCellStyle.BackColor = Color.FromArgb(244, 243, 234);
                }
            }

            dgv.Columns.AddRange(gridColumns);
        }
Exemplo n.º 17
0
        private void SubTopicDetails()
        {
            Sbd = new StringBuilder();
            Sbd.Remove(0, Sbd.Length);
            Sbd.Append("SELECT ");
            Sbd.Append("S.SubTopicName,");
            Sbd.Append("P.Para_Desc 'TopicStatus',");
            Sbd.Append("S.SubTopicId ");
            Sbd.Append("FROM SubTopic S ");
            Sbd.Append("INNER JOIN Parameter P ON P.Para_BPC = 'DetailsGroup' AND P.Para_Type = 'status' AND P.Para_Code	= S.SubTopicStatus ");
            Sbd.Append("WHERE S.SubTopicStatus <> 'I' ");
            Sbd.Append(" AND S.SubTopicId NOT IN (SELECT M.SubTopicId FROM MainTopicMappingDetail M ");
            Sbd.Append("INNER JOIN MainTopicMapping T ON M.TopicMappingId = T.TopicMappingId ");
            Sbd.Append("INNER JOIN DetailsGroup G ON G.DetailGroupId = T.DetailGroupId ");
            Sbd.Append("INNER JOIN SubSubject S ON S.SubSubjectId = G.SubSubjectId WHERE S.SubSubjectName = 'VFR' )");

            string sql = Sbd.ToString();

            Cmd = new SqlCommand();
            Cmd.Parameters.Clear();
            Cmd.CommandText = sql;
            Cmd.CommandType = CommandType.Text;
            Cmd.Connection  = Conn;

            Sdr = Cmd.ExecuteReader();
            if (Sdr.HasRows)
            {
                DataGridViewCheckBoxColumn chkColSelect = new DataGridViewCheckBoxColumn();
                chkColSelect.Name         = "chkSelect";
                chkColSelect.TrueValue    = true;
                chkColSelect.Width        = 130;
                chkColSelect.DisplayIndex = 18;
                chkColSelect.FlatStyle    = FlatStyle.Popup;
                dgv_SubTopic.Columns.Add(chkColSelect);



                DataTable dt = new DataTable();


                dt.Load(Sdr);
                dgv_SubTopic.DataSource = dt;

                DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
                column.HeaderText = "Style";
                column.Items.Add("Default");
                column.Items.Add("Additional");

                column.Name = "cmbName";

                dgv_SubTopic.Columns.Add(column);



                dgv_SubTopic.ClearSelection();
                lbSumList.Text = "Count Sub-Topic :     " + dgv_SubTopic.Rows.Count.ToString();

                dgv_Header();
            }
            else
            {
                dgv_SubTopic.DataSource = null;
            }
            Sdr.Close();
        }
Exemplo n.º 18
0
 /// <summary>
 /// Fill a list by the specified Enum type.
 /// </summary>
 /// <typeparam name="TEnum">The type of a Enum.</typeparam>
 /// <param name="list">A DataGridViewComboBoxColumn.</param>
 /// <param name="firstIsEmpty">True: the first item should be empty.</param>
 public static void Fill <TEnum>(DataGridViewComboBoxColumn list, bool firstIsEmpty) where TEnum : struct
 {
     FillDropdown <DataGridViewComboBoxColumn, TEnum>(list, firstIsEmpty);
 }
        private void PopulateListStudentAttendance()
        {
            if (!isFormLoaded)
            {
                return;
            }
            timeTable = _timeTableservice.GetTimeTableByID(Convert.ToInt32(cbxClassSchedule.SelectedValue));

            if (cbxClassSchedule.SelectedValue != null)
            {
                List <LecturerStudentAttendanceItem> studentAttendanceItems = _studentAttendanceService.GetLecturerStudentAttendance(timeTable.LecturerID, timeTable.IntakeID, timeTable.SubjectID, timeTable.SubjectDay, ((DateTime.Now.DayOfYear + 3) / 7));

                DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
                var presenceStatuses           = _presenceStatus.GetAll();
                presenceStatuses.Insert(0, new PresenceStatus {
                    PresenceStatusID = 0, PresenceStatusName = "Select Status"
                });
                cmb.DataSource       = presenceStatuses;
                cmb.DisplayMember    = "PresenceStatusName";
                cmb.ValueMember      = "PresenceStatusID";
                cmb.HeaderText       = "PresenceStatus";
                cmb.Name             = "PresenceStatus";
                cmb.DataPropertyName = "PresenceStatus";

                dgvStudentAttendance.Rows.Clear();
                dgvStudentAttendance.ReadOnly        = false;
                dgvStudentAttendance.ColumnCount     = 9;
                dgvStudentAttendance.Columns[0].Name = "StudentAttendanceID";
                dgvStudentAttendance.Columns[1].Name = "StudentID";
                dgvStudentAttendance.Columns[2].Name = "IntakeID";
                dgvStudentAttendance.Columns[3].Name = "SubjectID";
                dgvStudentAttendance.Columns[4].Name = "LecturerID";
                dgvStudentAttendance.Columns[5].Name = "DayOfWeek";
                dgvStudentAttendance.Columns[6].Name = "WeekOfYear";
                dgvStudentAttendance.Columns[7].Name = "Date";
                dgvStudentAttendance.Columns[8].Name = "Student Name";
                dgvStudentAttendance.Columns.Add(cmb);

                dgvStudentAttendance.Columns["StudentAttendanceID"].Visible = false;
                dgvStudentAttendance.Columns["WeekOfYear"].Visible          = false;
                dgvStudentAttendance.Columns["DayOfWeek"].Visible           = false;
                dgvStudentAttendance.Columns["Date"].Visible       = false;
                dgvStudentAttendance.Columns["LecturerID"].Visible = false;
                dgvStudentAttendance.Columns["SubjectID"].Visible  = false;

                dgvStudentAttendance.Columns["StudentID"].ReadOnly    = true;
                dgvStudentAttendance.Columns["IntakeID"].ReadOnly     = true;
                dgvStudentAttendance.Columns["Student NAme"].ReadOnly = true;

                for (int i = 0; i < studentAttendanceItems.Count; i++)
                {
                    string[] row = new string[] {
                        studentAttendanceItems[i].StudentAttendanceID.ToString(),
                        studentAttendanceItems[i].StudentID,
                        studentAttendanceItems[i].IntakeID,
                        studentAttendanceItems[i].SubjectID.ToString(),
                        studentAttendanceItems[i].LecturerID,
                        studentAttendanceItems[i].DayOfWeek.ToString(),
                        studentAttendanceItems[i].WeekOfyear.ToString(),
                        studentAttendanceItems[i].Date.ToString(),
                        studentAttendanceItems[i].StudentFullName.ToString()
                    };
                    dgvStudentAttendance.Rows.Add(row);
                    dgvStudentAttendance.Rows[i].Cells["PresenceStatus"].Value = studentAttendanceItems[i].PresenceStatusID;
                }

                if (dgvStudentAttendance.Rows.Count == 0)
                {
                    btnPublishStudentAttendance.Enabled = false;
                }
                else
                {
                    btnPublishStudentAttendance.Enabled = true;
                }
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Fill a list by the specified data.
 /// </summary>
 /// <param name="list">A DataGridViewComboBoxColumn.</param>
 /// <param name="items">The data used to fill <paramref name="list"/>.</param>
 /// <param name="firstIsEmpty">True: the first item should be empty.</param>
 public static void Fill(DataGridViewComboBoxColumn list, IEnumerable <DropdownItem> items, bool firstIsEmpty)
 {
     FillDropdown <DataGridViewComboBoxColumn>(list, items, firstIsEmpty);
 }
Exemplo n.º 21
0
        private void SearchBanksForm_Load(object sender, EventArgs e)
        {
            try
            {
                AccountFields.Add(new Field("banksortcode", "string"));
                AccountFields.Add(new Field("bankcode", "string"));
                AccountFields.Add(new Field("bankname", "string"));
                AccountFields.Add(new Field("branchcode", "string"));
                AccountFields.Add(new Field("branchname", "string"));

                cbField.DataSource    = AccountFields;
                cbField.DisplayMember = "Name";
                cbField.ValueMember   = "Name";

                cbOperator.DataSource    = Op.GetList();
                cbOperator.DisplayMember = "Description";
                cbOperator.ValueMember   = "Symbol";

                lstCriteria.DataSource = criteriaBuilder.CriterionItemList();

                var _Banksquery = from b in db.Banks
                                  select b;
                List <Bank> _Banks = _Banksquery.ToList();


                DataGridViewComboBoxColumn colBank = new DataGridViewComboBoxColumn();
                colBank.HeaderText                 = "Bank";
                colBank.Name                       = "cbBank";
                colBank.DataSource                 = _Banks;
                colBank.DisplayMember              = "BankName";
                colBank.DataPropertyName           = "BankCode";
                colBank.ValueMember                = "BankCode";
                colBank.MaxDropDownItems           = 10;
                colBank.DisplayIndex               = 4;
                colBank.MinimumWidth               = 5;
                colBank.Width                      = 200;
                colBank.AutoSizeMode               = DataGridViewAutoSizeColumnMode.Fill;
                colBank.FlatStyle                  = FlatStyle.Flat;
                colBank.DefaultCellStyle.NullValue = "--- Select ---";
                colBank.ReadOnly                   = true;
                if (!this.dataGridViewBanks.Columns.Contains("cbBank"))
                {
                    dataGridViewBanks.Columns.Add(colBank);
                }

                var _BankBranchesquery = from bb in db.BankBranches
                                         select bb;
                List <BankBranch> _BankBranches = _BankBranchesquery.ToList();

                DataGridViewComboBoxColumn colBranch = new DataGridViewComboBoxColumn();
                colBranch.HeaderText                 = "Branch";
                colBranch.Name                       = "cbBranch";
                colBranch.DataSource                 = _BankBranches;
                colBranch.DisplayMember              = "BranchName";
                colBranch.DataPropertyName           = "BankSortCode";
                colBranch.ValueMember                = "BankSortCode";
                colBranch.MaxDropDownItems           = 10;
                colBranch.DisplayIndex               = 3;
                colBranch.MinimumWidth               = 5;
                colBranch.Width                      = 150;
                colBranch.FlatStyle                  = FlatStyle.Flat;
                colBranch.DefaultCellStyle.NullValue = "--- Select ---";
                colBranch.ReadOnly                   = true;
                if (!this.dataGridViewBanks.Columns.Contains("cbBranch"))
                {
                    dataGridViewBanks.Columns.Add(colBranch);
                }

                this.dataGridViewBanks.AutoGenerateColumns = false;
                this.dataGridViewBanks.SelectionMode       = DataGridViewSelectionMode.FullRowSelect;
            }
            catch (Exception ex)
            {
                Utils.ShowError(ex);
            }
        }
Exemplo n.º 22
0
        private void GenerarColumnas()
        {
            // Creando la columna Nro. Documento
            DataGridViewTextBoxColumn colNroDoc = new DataGridViewTextBoxColumn();

            // Creamos la nueva columna y definimos el tipo de columna
            colNroDoc.Name = "nro_doc";
            // Asignamos un nombre a la columna
            colNroDoc.HeaderText = "Nro. Documento";
            // Indicamos el título a mostrar
            colNroDoc.DataPropertyName = "nro_doc";
            // Indicamos con cual columna del DataTable que asignamos al
            // DataSource de la grilla debe vincularse
            colNroDoc.DisplayIndex = 0;
            // En que posición debe mostrarse, todas las columnas a la derecha
            // de la posición que indiquemos se moverán una posción a la derecha

            this.dgvUsuarios.Columns.Add(colNroDoc);
            // Agregamos la columna al DataGridView para que la muestre

            // Creando la columna Tipo Documento
            DataGridViewComboBoxColumn colTipoDoc = new DataGridViewComboBoxColumn();

            colTipoDoc.Name             = "tipo_doc";
            colTipoDoc.HeaderText       = "Tipo Documento";
            colTipoDoc.DataPropertyName = "tipo_doc";
            colTipoDoc.DisplayIndex     = 0;

            /*
             * // Agrego items manualmente
             * colTipoDoc.Items.Add(1);
             * colTipoDoc.Items.Add(2);
             * colTipoDoc.Items.Add(3);
             * colTipoDoc.Items.Add(4);
             * colTipoDoc.Items.Add(5);
             */

            colTipoDoc.DataSource = this.getTiposDocumento();
            // Asigno la lista de items que son válidos

            colTipoDoc.ValueMember = "cod_tipo_doc";
            // Indico que el valor interno del combo es el
            // valor de la fila elegida y la columna cod_tipo_doc
            // del DataSource que asigné a la columna colTipoDoc

            colTipoDoc.DisplayMember = "desc_tipo_doc";
            // Indico que el valor que se muestra al usuario es el
            // que se corresponde con la columna desc_tipo_doc
            // del DataSource que asigné a colTipoDoc independientemente
            // de la columna de la cual obtiene su valor

            this.dgvUsuarios.Columns.Add(colTipoDoc);

            DataGridViewTextBoxColumn colTel = new DataGridViewTextBoxColumn();

            colTel.Name             = "telefono";
            colTel.HeaderText       = "Teléfono";
            colTel.DataPropertyName = "telefono";

            DataGridViewTextBoxColumn colEmail = new DataGridViewTextBoxColumn();

            colEmail.Name             = "email";
            colEmail.HeaderText       = "E-Mail";
            colEmail.DataPropertyName = "email";

            DataGridViewTextBoxColumn colCel = new DataGridViewTextBoxColumn();

            colCel.Name             = "celular";
            colCel.HeaderText       = "Celular";
            colCel.DataPropertyName = "celular";

            DataGridViewTextBoxColumn colUsuario = new DataGridViewTextBoxColumn();

            colUsuario.Name             = "usuario";
            colUsuario.HeaderText       = "Usuario";
            colUsuario.DataPropertyName = "usuario";

            DataGridViewTextBoxColumn colClave = new DataGridViewTextBoxColumn();

            colClave.Name             = "clave";
            colClave.HeaderText       = "Clave";
            colClave.DataPropertyName = "clave";


            colEmail.Width = 250;
            colNroDoc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            colClave.Visible = false;

            // Como las columnas direccion, nombre, apellido y fecha de nacimiento las creamos
            // con el diseñador de formularios no disponemos de una variable para hacer
            // referencia a ellas. Entonces debemos referenciarlas con
            // this.dgvUsuarios.Columns["nombre_columna"] donde el nombre_columna es lo que
            // indicamos en la propiedad Name de las columnas
            this.dgvUsuarios.Columns["direccion"].Width = 250;
            this.dgvUsuarios.Columns["apellido"].DefaultCellStyle.Font =
                new Font(this.dgvUsuarios.DefaultCellStyle.Font, FontStyle.Bold);
            this.dgvUsuarios.Columns["nombre"].DefaultCellStyle.Font =
                new Font(this.dgvUsuarios.DefaultCellStyle.Font, FontStyle.Bold);
            this.dgvUsuarios.Columns["fecha_nac"].DefaultCellStyle.Alignment =
                DataGridViewContentAlignment.MiddleRight;

            this.dgvUsuarios.Columns.Add(colTel);
            this.dgvUsuarios.Columns.Add(colEmail);
            this.dgvUsuarios.Columns.Add(colCel);
            this.dgvUsuarios.Columns.Add(colUsuario);
            this.dgvUsuarios.Columns.Add(colClave);
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var form = new Form();
            var dg   = new DataGridView {
                Dock = DockStyle.Fill, Parent = form
            };

            dg.AllowUserToAddRows = dg.AllowUserToDeleteRows = false;
            var colId = new DataGridViewTextBoxColumn {
                HeaderText = "Id", ReadOnly = true
            };
            var colName = new DataGridViewTextBoxColumn {
                HeaderText = "Name"
            };
            var colCity = new DataGridViewComboBoxColumn {
                HeaderText = "City"
            };
            var colAction = new DataGridViewButtonColumn {
                HeaderText = "Action"
            };

            colName.ReadOnly     = true;
            colCity.ReadOnly     = true;
            colCity.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            colAction.Text       = "Edit";
            dg.Columns.AddRange(colId, colName, colCity, colAction);
            var data = new[]
            {
                new { Id = 1, Name = "Mitch", City = "Kolkata" },
                new { Id = 2, Name = "Simon", City = "Delhi" },
                new { Id = 3, Name = "Poly", City = "Madras" },
            };

            colCity.Items.AddRange(data.Select(item => item.City).Distinct().ToArray());
            foreach (var item in data)
            {
                dg.Rows.Add(item.Id, item.Name, item.City, "Edit");
            }
            Action <DataGridViewRow> enterEditMode = row =>
            {
                var cellName   = (DataGridViewTextBoxCell)row.Cells[colName.Index];
                var cellCity   = (DataGridViewComboBoxCell)row.Cells[colCity.Index];
                var cellAction = (DataGridViewButtonCell)row.Cells[colAction.Index];
                cellName.ReadOnly     = false;
                cellCity.ReadOnly     = false;
                cellCity.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                dg.CurrentCell        = cellName;
                dg.BeginEdit(true);
                cellAction.Value = "Save";
            };
            Action <DataGridViewRow> exitEditMode = row =>
            {
                var cellName   = (DataGridViewTextBoxCell)row.Cells[colName.Index];
                var cellCity   = (DataGridViewComboBoxCell)row.Cells[colCity.Index];
                var cellAction = (DataGridViewButtonCell)row.Cells[colAction.Index];
                cellName.ReadOnly     = true;
                cellCity.ReadOnly     = true;
                cellCity.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                cellAction.Value      = "Edit";
            };

            dg.CellContentClick += (sender, e) =>
            {
                if (e.ColumnIndex == colAction.Index)
                {
                    var row        = dg.Rows[e.RowIndex];
                    var cellAction = (DataGridViewButtonCell)row.Cells[colAction.Index];
                    if ((string)cellAction.Value == "Edit")
                    {
                        enterEditMode(row);
                    }
                    else if (dg.EndEdit())
                    {
                        // Save code goes here ...
                        exitEditMode(row);
                    }
                }
            };
            dg.RowValidated += (sender, e) =>
            {
                var row        = dg.Rows[e.RowIndex];
                var cellAction = (DataGridViewButtonCell)row.Cells[colAction.Index];
                if ((string)cellAction.Value == "Save")
                {
                    exitEditMode(row);
                }
            };
            Application.Run(form);
        }
Exemplo n.º 24
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(QuestionSetEditor));
     this.groupBox2                                  = new System.Windows.Forms.GroupBox();
     this.questionSetsDataGrid                       = new System.Windows.Forms.DataGridView();
     this.idDataGridViewTextBoxColumn                = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.typeIdDataGridViewTextBoxColumn            = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.subtypeIdDataGridViewTextBoxColumn         = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.difficultyLevelIdDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.dataGridViewTextBoxColumn1                 = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.pictureDataGridViewImageColumn             = new System.Windows.Forms.DataGridViewImageColumn();
     this.difficultyLevel                            = new System.Windows.Forms.DataGridViewComboBoxColumn();
     this.TypeId    = new System.Windows.Forms.DataGridViewComboBoxColumn();
     this.SubtypeId = new System.Windows.Forms.DataGridViewComboBoxColumn();
     this.Idpas     = new System.Windows.Forms.DataGridViewComboBoxColumn();
     this.setIdDataGridViewTextBoxColumn         = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.questionOrderDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.questionZoneDataGridViewTextBoxColumn  = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.questionIdDataGridViewTextBoxColumn    = new System.Windows.Forms.DataGridViewTextBoxColumn();
     this.buttonUp               = new System.Windows.Forms.Button();
     this.imageList              = new System.Windows.Forms.ImageList(this.components);
     this.addExistingButton      = new System.Windows.Forms.Button();
     this.addNewButton           = new System.Windows.Forms.Button();
     this.removeButton           = new System.Windows.Forms.Button();
     this.buttonDown             = new System.Windows.Forms.Button();
     this.groupBox1              = new System.Windows.Forms.GroupBox();
     this.inZone3                = new System.Windows.Forms.Label();
     this.inZone2                = new System.Windows.Forms.Label();
     this.inZone1                = new System.Windows.Forms.Label();
     this.label8                 = new System.Windows.Forms.Label();
     this.label6                 = new System.Windows.Forms.Label();
     this.label4                 = new System.Windows.Forms.Label();
     this.typeLable              = new System.Windows.Forms.Label();
     this.timeLable              = new System.Windows.Forms.Label();
     this.numberOfQuestionsLable = new System.Windows.Forms.Label();
     this.label1                 = new System.Windows.Forms.Label();
     this.label5                 = new System.Windows.Forms.Label();
     this.label7                 = new System.Windows.Forms.Label();
     this.groupBox3              = new System.Windows.Forms.GroupBox();
     this.descriptionTextBox     = new System.Windows.Forms.TextBox();
     this.nameTextBox            = new System.Windows.Forms.TextBox();
     this.label2                 = new System.Windows.Forms.Label();
     this.label3                 = new System.Windows.Forms.Label();
     ((System.ComponentModel.ISupportInitialize)(this.data)).BeginInit();
     this.groupBox2.SuspendLayout();
     ((System.ComponentModel.ISupportInitialize)(this.questionSetsDataGrid)).BeginInit();
     this.groupBox1.SuspendLayout();
     this.groupBox3.SuspendLayout();
     this.SuspendLayout();
     //
     // groupBox2
     //
     this.groupBox2.Controls.Add(this.questionSetsDataGrid);
     this.groupBox2.Controls.Add(this.buttonUp);
     this.groupBox2.Controls.Add(this.addExistingButton);
     this.groupBox2.Controls.Add(this.addNewButton);
     this.groupBox2.Controls.Add(this.removeButton);
     this.groupBox2.Controls.Add(this.buttonDown);
     this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.groupBox2.Location  = new System.Drawing.Point(3, 248);
     this.groupBox2.Name      = "groupBox2";
     this.groupBox2.Size      = new System.Drawing.Size(774, 381);
     this.groupBox2.TabIndex  = 9;
     this.groupBox2.TabStop   = false;
     this.groupBox2.Text      = "Questions";
     //
     // questionSetsDataGrid
     //
     this.questionSetsDataGrid.AllowUserToAddRows          = false;
     this.questionSetsDataGrid.AllowUserToDeleteRows       = false;
     this.questionSetsDataGrid.AllowUserToOrderColumns     = true;
     this.questionSetsDataGrid.AutoGenerateColumns         = false;
     this.questionSetsDataGrid.ColumnHeadersBorderStyle    = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
     this.questionSetsDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     this.questionSetsDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
         this.idDataGridViewTextBoxColumn,
         this.typeIdDataGridViewTextBoxColumn,
         this.subtypeIdDataGridViewTextBoxColumn,
         this.difficultyLevelIdDataGridViewTextBoxColumn,
         this.dataGridViewTextBoxColumn1,
         this.pictureDataGridViewImageColumn,
         this.difficultyLevel,
         this.TypeId,
         this.SubtypeId,
         this.Idpas,
         this.setIdDataGridViewTextBoxColumn,
         this.questionOrderDataGridViewTextBoxColumn,
         this.questionZoneDataGridViewTextBoxColumn,
         this.questionIdDataGridViewTextBoxColumn
     });
     this.questionSetsDataGrid.DataMember       = "QuestionsEx";
     this.questionSetsDataGrid.DataSource       = this.data;
     this.questionSetsDataGrid.Location         = new System.Drawing.Point(5, 46);
     this.questionSetsDataGrid.MultiSelect      = false;
     this.questionSetsDataGrid.Name             = "questionSetsDataGrid";
     this.questionSetsDataGrid.ReadOnly         = true;
     this.questionSetsDataGrid.SelectionMode    = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
     this.questionSetsDataGrid.Size             = new System.Drawing.Size(759, 329);
     this.questionSetsDataGrid.TabIndex         = 11;
     this.questionSetsDataGrid.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.questionSetsDataGrid_CellDoubleClick);
     this.questionSetsDataGrid.DataError       += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.questionSetsDataGrid_DataError);
     //
     // idDataGridViewTextBoxColumn
     //
     this.idDataGridViewTextBoxColumn.DataPropertyName = "Id";
     this.idDataGridViewTextBoxColumn.HeaderText       = "Id";
     this.idDataGridViewTextBoxColumn.Name             = "idDataGridViewTextBoxColumn";
     this.idDataGridViewTextBoxColumn.ReadOnly         = true;
     this.idDataGridViewTextBoxColumn.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     this.idDataGridViewTextBoxColumn.Visible          = false;
     //
     // typeIdDataGridViewTextBoxColumn
     //
     this.typeIdDataGridViewTextBoxColumn.DataPropertyName = "TypeId";
     this.typeIdDataGridViewTextBoxColumn.HeaderText       = "TypeId";
     this.typeIdDataGridViewTextBoxColumn.Name             = "typeIdDataGridViewTextBoxColumn";
     this.typeIdDataGridViewTextBoxColumn.ReadOnly         = true;
     this.typeIdDataGridViewTextBoxColumn.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     this.typeIdDataGridViewTextBoxColumn.Visible          = false;
     //
     // subtypeIdDataGridViewTextBoxColumn
     //
     this.subtypeIdDataGridViewTextBoxColumn.DataPropertyName = "SubtypeId";
     this.subtypeIdDataGridViewTextBoxColumn.HeaderText       = "SubtypeId";
     this.subtypeIdDataGridViewTextBoxColumn.Name             = "subtypeIdDataGridViewTextBoxColumn";
     this.subtypeIdDataGridViewTextBoxColumn.ReadOnly         = true;
     this.subtypeIdDataGridViewTextBoxColumn.Visible          = false;
     //
     // difficultyLevelIdDataGridViewTextBoxColumn
     //
     this.difficultyLevelIdDataGridViewTextBoxColumn.DataPropertyName = "DifficultyLevelId";
     this.difficultyLevelIdDataGridViewTextBoxColumn.HeaderText       = "DifficultyLevelId";
     this.difficultyLevelIdDataGridViewTextBoxColumn.Name             = "difficultyLevelIdDataGridViewTextBoxColumn";
     this.difficultyLevelIdDataGridViewTextBoxColumn.ReadOnly         = true;
     this.difficultyLevelIdDataGridViewTextBoxColumn.Visible          = false;
     //
     // dataGridViewTextBoxColumn1
     //
     this.dataGridViewTextBoxColumn1.DataPropertyName = "Text";
     this.dataGridViewTextBoxColumn1.HeaderText       = "Text";
     this.dataGridViewTextBoxColumn1.Name             = "dataGridViewTextBoxColumn1";
     this.dataGridViewTextBoxColumn1.ReadOnly         = true;
     this.dataGridViewTextBoxColumn1.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     //
     // pictureDataGridViewImageColumn
     //
     this.pictureDataGridViewImageColumn.DataPropertyName = "Picture";
     this.pictureDataGridViewImageColumn.HeaderText       = "Picture";
     this.pictureDataGridViewImageColumn.ImageLayout      = System.Windows.Forms.DataGridViewImageCellLayout.Zoom;
     this.pictureDataGridViewImageColumn.Name             = "pictureDataGridViewImageColumn";
     this.pictureDataGridViewImageColumn.ReadOnly         = true;
     //
     // difficultyLevel
     //
     this.difficultyLevel.DataPropertyName = "DifficultyLevelId";
     this.difficultyLevel.DataSource       = this.data;
     this.difficultyLevel.DisplayMember    = "DifficultyLevel.Name";
     this.difficultyLevel.DisplayStyle     = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
     this.difficultyLevel.HeaderText       = "Difficulty level";
     this.difficultyLevel.Name             = "difficultyLevel";
     this.difficultyLevel.ReadOnly         = true;
     this.difficultyLevel.ValueMember      = "DifficultyLevel.Id";
     //
     // TypeId
     //
     this.TypeId.DataPropertyName = "TypeId";
     this.TypeId.DataSource       = this.data;
     this.TypeId.DisplayMember    = "QuestionTypes.Name";
     this.TypeId.DisplayStyle     = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
     this.TypeId.HeaderText       = "Type";
     this.TypeId.Name             = "TypeId";
     this.TypeId.ReadOnly         = true;
     this.TypeId.ValueMember      = "QuestionTypes.Id";
     //
     // SubtypeId
     //
     this.SubtypeId.DataPropertyName = "SubtypeId";
     this.SubtypeId.DataSource       = this.data;
     this.SubtypeId.DisplayMember    = "QuestionSubtypes.Name";
     this.SubtypeId.DisplayStyle     = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
     this.SubtypeId.HeaderText       = "Subtype";
     this.SubtypeId.Name             = "SubtypeId";
     this.SubtypeId.ReadOnly         = true;
     this.SubtypeId.ValueMember      = "QuestionSubtypes.Id";
     this.SubtypeId.Width            = 250;
     //
     // Idpas
     //
     this.Idpas.AutoComplete     = false;
     this.Idpas.DataPropertyName = "QuestionId";
     this.Idpas.DataSource       = this.data;
     this.Idpas.DisplayMember    = "PassagesToQuestionsEx.Text";
     this.Idpas.DisplayStyle     = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
     this.Idpas.HeaderText       = "Passage";
     this.Idpas.Name             = "Idpas";
     this.Idpas.ReadOnly         = true;
     this.Idpas.ValueMember      = "PassagesToQuestionsEx.Id";
     this.Idpas.Visible          = false;
     this.Idpas.Width            = 200;
     //
     // setIdDataGridViewTextBoxColumn
     //
     this.setIdDataGridViewTextBoxColumn.DataPropertyName = "SetId";
     this.setIdDataGridViewTextBoxColumn.HeaderText       = "SetId";
     this.setIdDataGridViewTextBoxColumn.Name             = "setIdDataGridViewTextBoxColumn";
     this.setIdDataGridViewTextBoxColumn.ReadOnly         = true;
     this.setIdDataGridViewTextBoxColumn.Visible          = false;
     //
     // questionOrderDataGridViewTextBoxColumn
     //
     this.questionOrderDataGridViewTextBoxColumn.DataPropertyName = "QuestionOrder";
     this.questionOrderDataGridViewTextBoxColumn.HeaderText       = "QuestionOrder";
     this.questionOrderDataGridViewTextBoxColumn.Name             = "questionOrderDataGridViewTextBoxColumn";
     this.questionOrderDataGridViewTextBoxColumn.ReadOnly         = true;
     this.questionOrderDataGridViewTextBoxColumn.Visible          = false;
     //
     // questionZoneDataGridViewTextBoxColumn
     //
     this.questionZoneDataGridViewTextBoxColumn.DataPropertyName = "QuestionZone";
     this.questionZoneDataGridViewTextBoxColumn.HeaderText       = "QuestionZone";
     this.questionZoneDataGridViewTextBoxColumn.Name             = "questionZoneDataGridViewTextBoxColumn";
     this.questionZoneDataGridViewTextBoxColumn.ReadOnly         = true;
     this.questionZoneDataGridViewTextBoxColumn.SortMode         = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     this.questionZoneDataGridViewTextBoxColumn.Visible          = false;
     //
     // questionIdDataGridViewTextBoxColumn
     //
     this.questionIdDataGridViewTextBoxColumn.DataPropertyName = "QuestionId";
     this.questionIdDataGridViewTextBoxColumn.HeaderText       = "QuestionId";
     this.questionIdDataGridViewTextBoxColumn.Name             = "questionIdDataGridViewTextBoxColumn";
     this.questionIdDataGridViewTextBoxColumn.ReadOnly         = true;
     this.questionIdDataGridViewTextBoxColumn.Visible          = false;
     //
     // buttonUp
     //
     this.buttonUp.FlatStyle  = System.Windows.Forms.FlatStyle.Popup;
     this.buttonUp.ImageIndex = 0;
     this.buttonUp.ImageList  = this.imageList;
     this.buttonUp.Location   = new System.Drawing.Point(8, 16);
     this.buttonUp.Name       = "buttonUp";
     this.buttonUp.Size       = new System.Drawing.Size(17, 24);
     this.buttonUp.TabIndex   = 10;
     this.buttonUp.Click     += new System.EventHandler(this.buttonUp_Click);
     //
     // imageList
     //
     this.imageList.ImageStream      = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
     this.imageList.TransparentColor = System.Drawing.Color.Fuchsia;
     this.imageList.Images.SetKeyName(0, "");
     this.imageList.Images.SetKeyName(1, "");
     //
     // addExistingButton
     //
     this.addExistingButton.Anchor     = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.addExistingButton.FlatStyle  = System.Windows.Forms.FlatStyle.System;
     this.addExistingButton.ImageIndex = 1;
     this.addExistingButton.Location   = new System.Drawing.Point(488, 16);
     this.addExistingButton.Name       = "addExistingButton";
     this.addExistingButton.Size       = new System.Drawing.Size(88, 24);
     this.addExistingButton.TabIndex   = 7;
     this.addExistingButton.Text       = "Add &Existing...";
     this.addExistingButton.Click     += new System.EventHandler(this.addExistingButton_Click);
     //
     // addNewButton
     //
     this.addNewButton.Anchor     = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.addNewButton.FlatStyle  = System.Windows.Forms.FlatStyle.System;
     this.addNewButton.ImageIndex = 0;
     this.addNewButton.Location   = new System.Drawing.Point(582, 16);
     this.addNewButton.Name       = "addNewButton";
     this.addNewButton.Size       = new System.Drawing.Size(88, 24);
     this.addNewButton.TabIndex   = 8;
     this.addNewButton.Text       = "Add &New...";
     this.addNewButton.Click     += new System.EventHandler(this.addNewButton_Click);
     //
     // removeButton
     //
     this.removeButton.Anchor     = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.removeButton.FlatStyle  = System.Windows.Forms.FlatStyle.System;
     this.removeButton.ImageIndex = 2;
     this.removeButton.Location   = new System.Drawing.Point(676, 16);
     this.removeButton.Name       = "removeButton";
     this.removeButton.Size       = new System.Drawing.Size(88, 24);
     this.removeButton.TabIndex   = 9;
     this.removeButton.Text       = "&Remove";
     this.removeButton.Click     += new System.EventHandler(this.removeButton_Click);
     //
     // buttonDown
     //
     this.buttonDown.FlatStyle  = System.Windows.Forms.FlatStyle.Popup;
     this.buttonDown.ImageIndex = 1;
     this.buttonDown.ImageList  = this.imageList;
     this.buttonDown.Location   = new System.Drawing.Point(27, 16);
     this.buttonDown.Name       = "buttonDown";
     this.buttonDown.Size       = new System.Drawing.Size(17, 24);
     this.buttonDown.TabIndex   = 10;
     this.buttonDown.Click     += new System.EventHandler(this.buttonDown_Click);
     //
     // groupBox1
     //
     this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.groupBox1.Controls.Add(this.inZone3);
     this.groupBox1.Controls.Add(this.inZone2);
     this.groupBox1.Controls.Add(this.inZone1);
     this.groupBox1.Controls.Add(this.label8);
     this.groupBox1.Controls.Add(this.label6);
     this.groupBox1.Controls.Add(this.label4);
     this.groupBox1.Controls.Add(this.typeLable);
     this.groupBox1.Controls.Add(this.timeLable);
     this.groupBox1.Controls.Add(this.numberOfQuestionsLable);
     this.groupBox1.Controls.Add(this.label1);
     this.groupBox1.Controls.Add(this.label5);
     this.groupBox1.Controls.Add(this.label7);
     this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.groupBox1.Location  = new System.Drawing.Point(542, 5);
     this.groupBox1.Name      = "groupBox1";
     this.groupBox1.Size      = new System.Drawing.Size(237, 126);
     this.groupBox1.TabIndex  = 11;
     this.groupBox1.TabStop   = false;
     this.groupBox1.Text      = "Information";
     //
     // inZone3
     //
     this.inZone3.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.inZone3.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.inZone3.Location  = new System.Drawing.Point(147, 93);
     this.inZone3.Name      = "inZone3";
     this.inZone3.Size      = new System.Drawing.Size(80, 16);
     this.inZone3.TabIndex  = 22;
     this.inZone3.Text      = "999";
     this.inZone3.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // inZone2
     //
     this.inZone2.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.inZone2.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.inZone2.Location  = new System.Drawing.Point(147, 78);
     this.inZone2.Name      = "inZone2";
     this.inZone2.Size      = new System.Drawing.Size(80, 16);
     this.inZone2.TabIndex  = 21;
     this.inZone2.Text      = "999";
     this.inZone2.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // inZone1
     //
     this.inZone1.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.inZone1.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.inZone1.Location  = new System.Drawing.Point(147, 63);
     this.inZone1.Name      = "inZone1";
     this.inZone1.Size      = new System.Drawing.Size(80, 16);
     this.inZone1.TabIndex  = 20;
     this.inZone1.Text      = "999";
     this.inZone1.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // label8
     //
     this.label8.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label8.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label8.Location  = new System.Drawing.Point(11, 78);
     this.label8.Name      = "label8";
     this.label8.Size      = new System.Drawing.Size(104, 16);
     this.label8.TabIndex  = 19;
     this.label8.Text      = "Questions in zone 2";
     //
     // label6
     //
     this.label6.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label6.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label6.Location  = new System.Drawing.Point(11, 94);
     this.label6.Name      = "label6";
     this.label6.Size      = new System.Drawing.Size(104, 15);
     this.label6.TabIndex  = 18;
     this.label6.Text      = "Questions in zone 3";
     //
     // label4
     //
     this.label4.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label4.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label4.Location  = new System.Drawing.Point(11, 62);
     this.label4.Name      = "label4";
     this.label4.Size      = new System.Drawing.Size(104, 16);
     this.label4.TabIndex  = 17;
     this.label4.Text      = "Questions in zone 1";
     //
     // typeLable
     //
     this.typeLable.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.typeLable.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.typeLable.Location  = new System.Drawing.Point(107, 16);
     this.typeLable.Name      = "typeLable";
     this.typeLable.Size      = new System.Drawing.Size(120, 16);
     this.typeLable.TabIndex  = 12;
     this.typeLable.Text      = "Reading Comprehension";
     this.typeLable.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // timeLable
     //
     this.timeLable.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.timeLable.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.timeLable.Location  = new System.Drawing.Point(147, 32);
     this.timeLable.Name      = "timeLable";
     this.timeLable.Size      = new System.Drawing.Size(80, 16);
     this.timeLable.TabIndex  = 16;
     this.timeLable.Text      = "Unlimited";
     this.timeLable.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // numberOfQuestionsLable
     //
     this.numberOfQuestionsLable.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.numberOfQuestionsLable.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.numberOfQuestionsLable.Location  = new System.Drawing.Point(147, 47);
     this.numberOfQuestionsLable.Name      = "numberOfQuestionsLable";
     this.numberOfQuestionsLable.Size      = new System.Drawing.Size(80, 16);
     this.numberOfQuestionsLable.TabIndex  = 15;
     this.numberOfQuestionsLable.Text      = "999";
     this.numberOfQuestionsLable.TextAlign = System.Drawing.ContentAlignment.TopRight;
     //
     // label1
     //
     this.label1.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label1.Location  = new System.Drawing.Point(11, 15);
     this.label1.Name      = "label1";
     this.label1.Size      = new System.Drawing.Size(32, 16);
     this.label1.TabIndex  = 8;
     this.label1.Text      = "Type:";
     this.label1.Click    += new System.EventHandler(this.label1_Click);
     //
     // label5
     //
     this.label5.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label5.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label5.Location  = new System.Drawing.Point(11, 30);
     this.label5.Name      = "label5";
     this.label5.Size      = new System.Drawing.Size(80, 16);
     this.label5.TabIndex  = 9;
     this.label5.Text      = "Time Limit:";
     //
     // label7
     //
     this.label7.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     this.label7.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label7.Location  = new System.Drawing.Point(11, 46);
     this.label7.Name      = "label7";
     this.label7.Size      = new System.Drawing.Size(104, 16);
     this.label7.TabIndex  = 10;
     this.label7.Text      = "# of Questions:";
     //
     // groupBox3
     //
     this.groupBox3.Controls.Add(this.descriptionTextBox);
     this.groupBox3.Controls.Add(this.nameTextBox);
     this.groupBox3.Controls.Add(this.label2);
     this.groupBox3.Controls.Add(this.label3);
     this.groupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.groupBox3.Location  = new System.Drawing.Point(3, 3);
     this.groupBox3.Name      = "groupBox3";
     this.groupBox3.Size      = new System.Drawing.Size(531, 239);
     this.groupBox3.TabIndex  = 12;
     this.groupBox3.TabStop   = false;
     //
     // descriptionTextBox
     //
     this.descriptionTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.data, "Tests.Description", true));
     this.descriptionTextBox.Location  = new System.Drawing.Point(5, 56);
     this.descriptionTextBox.Multiline = true;
     this.descriptionTextBox.Name      = "descriptionTextBox";
     this.descriptionTextBox.Size      = new System.Drawing.Size(520, 177);
     this.descriptionTextBox.TabIndex  = 5;
     //
     // nameTextBox
     //
     this.nameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.data, "Tests.Name", true));
     this.nameTextBox.Location = new System.Drawing.Point(42, 14);
     this.nameTextBox.Name     = "nameTextBox";
     this.nameTextBox.Size     = new System.Drawing.Size(483, 20);
     this.nameTextBox.TabIndex = 2;
     //
     // label2
     //
     this.label2.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label2.Location  = new System.Drawing.Point(6, 17);
     this.label2.Name      = "label2";
     this.label2.Size      = new System.Drawing.Size(48, 17);
     this.label2.TabIndex  = 4;
     this.label2.Text      = "Name";
     //
     // label3
     //
     this.label3.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.label3.Location  = new System.Drawing.Point(6, 37);
     this.label3.Name      = "label3";
     this.label3.Size      = new System.Drawing.Size(64, 16);
     this.label3.TabIndex  = 3;
     this.label3.Text      = "Description";
     //
     // QuestionSetEditor
     //
     this.Controls.Add(this.groupBox3);
     this.Controls.Add(this.groupBox1);
     this.Controls.Add(this.groupBox2);
     this.Name   = "QuestionSetEditor";
     this.Size   = new System.Drawing.Size(782, 632);
     this.Enter += new System.EventHandler(this.QuestionSetEditor_Enter);
     this.Load  += new System.EventHandler(this.QuestionSetEditor_Load);
     ((System.ComponentModel.ISupportInitialize)(this.data)).EndInit();
     this.groupBox2.ResumeLayout(false);
     ((System.ComponentModel.ISupportInitialize)(this.questionSetsDataGrid)).EndInit();
     this.groupBox1.ResumeLayout(false);
     this.groupBox3.ResumeLayout(false);
     this.groupBox3.PerformLayout();
     this.ResumeLayout(false);
 }
            private void ConstructeZDataGridView()
            {
                var dgv = this;

                //
                dgv.ManipulateRows = true;
                dgv.ShowRowNumber  = true;
                //
                dgv.AutoGenerateColumns = false;
                dgv.EditMode            = DataGridViewEditMode.EditOnEnter;

                var dicimalStyle3 = new DataGridViewCellStyle();

                dicimalStyle3.Format = "0.###";

                // 创建数据列并绑定到数据源 ----------------------------------------------

                // -------------------------
                var combo = new DataGridViewComboBoxColumn();

                combo.DataSource       = Enum.GetValues(typeof(Operator_Bool));
                combo.DataPropertyName = "Fill";
                combo.Width            = 50;
                combo.Name             = "填方";
                combo.ToolTipText      = @"边坡为填方还是挖方";
                dgv.Columns.Add(combo);
                // 如果要设置对应单元格的值为某枚举项:combo.Item(combo.Index,行号).Value = Gender.Male;

                // -------------------------
                var column = new DataGridViewTextBoxColumn();

                column.DataPropertyName = "FirstSlopeRatio";
                column.ReadOnly         = true;
                column.Name             = "首级坡比";
                column.ToolTipText      = @"第一级子边坡的坡比,如果子边坡数量为0,则恒不满足此条件";
                column.Width            = 100;
                dgv.Columns.Add(column);
                // -------------------------

                column = new DataGridViewTextBoxColumn();
                column.DataPropertyName = "SlopeHeight";
                column.Name             = "总坡高(m)";
                column.ToolTipText      = @"整个边坡的总坡高";
                column.ReadOnly         = true;
                column.Width            = 100;
                dgv.Columns.Add(column);

                // -------------------------
                column = new DataGridViewTextBoxColumn();
                column.DataPropertyName = "SlopeLevel";
                column.Name             = "总坡级";
                column.ToolTipText      = @"整个边坡共有多少级子边坡";
                column.ReadOnly         = true;
                column.ValueType        = typeof(int);
                column.Width            = 100;
                dgv.Columns.Add(column);

                // -------------------------
                var prots = Options_Collections.CommonFillProtections.ToList();

                prots.AddRange(Options_Collections.CommonCutProtections);
                var protsBinding = new BindingList <string>(prots);

                combo = new DataGridViewComboBoxColumn();
                // combo.drow = DataGridViewComboBoxDisplayStyle.DropDownButton;
                combo.DataSource       = protsBinding;
                combo.DataPropertyName = "ProtectionMethod";
                combo.Name             = "防护";
                combo.ToolTipText      = @"当前面所有的条件都满足时,确定此边坡的具体防护形式";
                combo.MinimumWidth     = 100;
                combo.AutoSizeMode     = DataGridViewAutoSizeColumnMode.DisplayedCells;
                dgv.Columns.Add(combo);
                // -------------------------
                column = new DataGridViewTextBoxColumn();
                column.DataPropertyName = "ProtectionMethod";
                column.Name             = "防护";
                column.ToolTipText      = @"当前面所有的条件都满足时,确定此边坡的具体防护形式";
                column.MinimumWidth     = 100;
                column.AutoSizeMode     = DataGridViewAutoSizeColumnMode.DisplayedCells;
                dgv.Columns.Add(column);


                // 事件绑定 -------------------------------------------------------------
                dgv.CellClick += DgvOnCellClick;
                dgv.DataError += EZdgvOnDataError; // 响应表格中的数据类型不匹配等出错的情况
                                                   //dgv.CellContentClick += EZdgvOnCellContentClick;  // 响应表格中的按钮按下事件
                                                   //dgv.CurrentCellDirtyStateChanged += EZdgvOnCurrentCellDirtyStateChanged; // 在表格中Checkbox的值发生改变时立即作出响应
                Slopes.AddingNew += SlopesOnAddingNew;
            }
Exemplo n.º 26
0
        private void prepareBenchmarksTab()
        {
            benchmarksGrid.Rows.Clear();
            benchmarksGrid.Columns.Clear();

            List <Benchmark> benchmarks = SportsFestivalManagementController.getInstance.getAllBenchmarks();

            DataGridViewComboBoxColumn disciplineColumn = new DataGridViewComboBoxColumn();

            disciplineColumn.DataSource    = SportsFestivalManagementController.getInstance.getAllDisciplines();
            disciplineColumn.DisplayMember = "Name";
            disciplineColumn.ValueMember   = "DisciplineId";
            disciplineColumn.Name          = "Disziplin";
            disciplineColumn.AutoSizeMode  = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn ageFromColumn = new DataGridViewTextBoxColumn();

            ageFromColumn.Name         = "Alter: Von";
            ageFromColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn ageUntilColumn = new DataGridViewTextBoxColumn();

            ageUntilColumn.Name         = "Alter: Bis";
            ageUntilColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn genderColumn = new DataGridViewTextBoxColumn();

            genderColumn.Name         = "Geschlecht";
            genderColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn rankColumn = new DataGridViewTextBoxColumn();

            rankColumn.Name         = "Rang";
            rankColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn valueColumn = new DataGridViewTextBoxColumn();

            valueColumn.Name         = "Richtwert";
            valueColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            DataGridViewTextBoxColumn measureColumn = new DataGridViewTextBoxColumn();

            measureColumn.Name         = "Einheit";
            measureColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;


            benchmarksGrid.Columns.Add(disciplineColumn);
            benchmarksGrid.Columns.Add(ageFromColumn);
            benchmarksGrid.Columns.Add(ageUntilColumn);
            benchmarksGrid.Columns.Add(genderColumn);
            benchmarksGrid.Columns.Add(rankColumn);
            benchmarksGrid.Columns.Add(valueColumn);
            benchmarksGrid.Columns.Add(measureColumn);

            foreach (Benchmark benchmark in benchmarks)
            {
                object[] dataRow = new object[] {
                    benchmark.Discipline.DisciplineId,
                    benchmark.AgeFrom,
                    benchmark.AgeUntil,
                    benchmark.Gender == 'm' ? "männlich" : "weiblich",
                    benchmark.Rank == "bronze" ? "Bronze" : benchmark.Rank == "silver" ? "Silber" : "Gold",
                    benchmark.BenchmarkValue,
                    benchmark.Discipline.Measure.Name
                };
                benchmarksGrid.Rows.Add(dataRow);
            }
        }
Exemplo n.º 27
0
        private void InitView()
        {
            dgvMain.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn ColumnRecordID = new DataGridViewTextBoxColumn();

            ColumnRecordID.DataPropertyName = "RecordID";
            ColumnRecordID.Name             = "ColumnRecordID";
            ColumnRecordID.HeaderText       = "RecordID";
            ColumnRecordID.Visible          = false;
            ColumnRecordID.Width            = 30;
            ColumnRecordID.FillWeight       = 40F;
            ColumnRecordID.ReadOnly         = true;
            ColumnRecordID.DisplayIndex     = 0;
            dgvMain.Columns.Add(ColumnRecordID);

            DataGridViewTextBoxColumn ColumnOnCreditID = new DataGridViewTextBoxColumn();

            ColumnOnCreditID.DataPropertyName = "OnCreditID";
            ColumnOnCreditID.Name             = "ColumnOnCreditID";
            ColumnOnCreditID.HeaderText       = "GoodsID";
            ColumnOnCreditID.Visible          = false;
            ColumnOnCreditID.Width            = 30;
            ColumnOnCreditID.FillWeight       = 40F;
            ColumnOnCreditID.ReadOnly         = true;
            ColumnOnCreditID.DisplayIndex     = 1;
            dgvMain.Columns.Add(ColumnOnCreditID);

            DataGridViewAutoFilter.DataGridViewAutoFilterTextBoxColumn ColumnClientName = new DataGridViewAutoFilter.DataGridViewAutoFilterTextBoxColumn();
            ColumnClientName.DataPropertyName = "ClientName";
            ColumnClientName.Name             = "ColumnClientName";
            ColumnClientName.HeaderText       = "客户";
            ColumnClientName.Width            = 70;
            ColumnClientName.DisplayIndex     = 2;
            dgvMain.Columns.Add(ColumnClientName);

            DataGridViewTextBoxColumn ColumnRecordTime = new DataGridViewTextBoxColumn();

            ColumnRecordTime.DataPropertyName = "RecordTime";
            ColumnRecordTime.Name             = "ColumnRecordTime";
            ColumnRecordTime.HeaderText       = "时间";
            ColumnRecordTime.Width            = 120;
            ColumnRecordTime.DisplayIndex     = 3;
            dgvMain.Columns.Add(ColumnRecordTime);

            DataGridViewComboBoxColumn ColumnOpType = new DataGridViewComboBoxColumn();

            ColumnOpType.DataPropertyName = "OpType";
            ColumnOpType.DisplayMember    = "Name";
            ColumnOpType.ValueMember      = "Value";
            ColumnOpType.DataSource       = CGlobalInstance.Instance.dtOnCreditType;

            ColumnOpType.Name         = "ColumnOpType";
            ColumnOpType.HeaderText   = "操作";
            ColumnOpType.Width        = 70;
            ColumnOpType.DisplayIndex = 4;

            dgvMain.Columns.Add(ColumnOpType);

            DataGridViewTextBoxColumn ColumnLastNumber = new DataGridViewTextBoxColumn();

            ColumnLastNumber.DataPropertyName = "LastNumber";
            ColumnLastNumber.Name             = "ColumnLastNumber";
            ColumnLastNumber.HeaderText       = "上次余额";
            ColumnLastNumber.Width            = 120;
            ColumnLastNumber.DisplayIndex     = 5;
            dgvMain.Columns.Add(ColumnLastNumber);

            DataGridViewTextBoxColumn ColumnNumber = new DataGridViewTextBoxColumn();

            ColumnNumber.DataPropertyName = "Number";
            ColumnNumber.Name             = "ColumnNumber";
            ColumnNumber.HeaderText       = "发生金额";
            ColumnNumber.Width            = 70;
            ColumnNumber.DisplayIndex     = 6;
            dgvMain.Columns.Add(ColumnNumber);



            DataGridViewAutoFilter.DataGridViewAutoFilterTextBoxColumn ColumnEmployee = new DataGridViewAutoFilter.DataGridViewAutoFilterTextBoxColumn();
            ColumnEmployee.DataPropertyName = "Employee";
            ColumnEmployee.Name             = "ColumnEmployee";
            ColumnEmployee.HeaderText       = "员工";
            ColumnEmployee.Width            = 70;
            ColumnEmployee.DisplayIndex     = 7;
            dgvMain.Columns.Add(ColumnEmployee);


            DataGridViewTextBoxColumn ColumnRemark = new DataGridViewTextBoxColumn();

            ColumnRemark.DataPropertyName = "Remark";
            ColumnRemark.Name             = "ColumnRemark";
            ColumnRemark.HeaderText       = "备注";
            ColumnRemark.Width            = 70;
            ColumnRemark.DisplayIndex     = 8;
            dgvMain.Columns.Add(ColumnRemark);
        }
        /// <summary>
        /// 设置DataGridView的列
        /// 该函数主要设置列的类型,尤其要注意变成下拉框的列
        /// 列的可见性,只读性,HeadText都不要在这里设置,放在DataBindComplete事件中处理
        /// </summary>
        void setDataGridViewColumn()
        {
            dataGridView1.Columns.Clear();
            DataGridViewTextBoxColumn  tbc;
            DataGridViewComboBoxColumn cbc;
            DataGridViewCheckBoxColumn ckbc;

            // 先把所有的列都加好,基本属性附上
            foreach (DataColumn dc in dtInner.Columns)
            {
                // 要下拉框的特殊处理
                if (dc.ColumnName == "判定")
                {
                    cbc                  = new DataGridViewComboBoxColumn();
                    cbc.HeaderText       = dc.ColumnName;
                    cbc.Name             = dc.ColumnName;
                    cbc.ValueType        = dc.DataType;
                    cbc.DataPropertyName = dc.ColumnName;
                    cbc.SortMode         = DataGridViewColumnSortMode.NotSortable;
                    cbc.Items.Add("Y");
                    cbc.Items.Add("N");
                    dataGridView1.Columns.Add(cbc);
                    continue;
                }
                if (dc.ColumnName == "位置1")
                {
                    cbc                  = new DataGridViewComboBoxColumn();
                    cbc.HeaderText       = dc.ColumnName;
                    cbc.Name             = dc.ColumnName;
                    cbc.ValueType        = dc.DataType;
                    cbc.DataPropertyName = dc.ColumnName;
                    cbc.SortMode         = DataGridViewColumnSortMode.NotSortable;
                    cbc.Items.Add("东");
                    cbc.Items.Add("西");
                    dataGridView1.Columns.Add(cbc);
                    continue;
                }
                if (dc.ColumnName == "位置2")
                {
                    cbc                  = new DataGridViewComboBoxColumn();
                    cbc.HeaderText       = dc.ColumnName;
                    cbc.Name             = dc.ColumnName;
                    cbc.ValueType        = dc.DataType;
                    cbc.DataPropertyName = dc.ColumnName;
                    cbc.SortMode         = DataGridViewColumnSortMode.NotSortable;
                    cbc.Items.Add("左");
                    cbc.Items.Add("右");
                    cbc.Items.Add("底");
                    dataGridView1.Columns.Add(cbc);
                    continue;
                }

                // 根据数据类型自动生成列的关键信息
                switch (dc.DataType.ToString())
                {
                case "System.Int32":
                case "System.String":
                case "System.Double":
                case "System.DateTime":
                    tbc                  = new DataGridViewTextBoxColumn();
                    tbc.HeaderText       = dc.ColumnName;
                    tbc.Name             = dc.ColumnName;
                    tbc.ValueType        = dc.DataType;
                    tbc.DataPropertyName = dc.ColumnName;
                    tbc.SortMode         = DataGridViewColumnSortMode.NotSortable;
                    dataGridView1.Columns.Add(tbc);
                    break;

                case "System.Boolean":
                    ckbc                  = new DataGridViewCheckBoxColumn();
                    ckbc.HeaderText       = dc.ColumnName;
                    ckbc.Name             = dc.ColumnName;
                    ckbc.ValueType        = dc.DataType;
                    ckbc.DataPropertyName = dc.ColumnName;
                    ckbc.SortMode         = DataGridViewColumnSortMode.NotSortable;
                    dataGridView1.Columns.Add(ckbc);
                    break;
                }
            }
        }
Exemplo n.º 29
0
        public StockEditor(DataTable table, QuoteCom quotecom, TaiFexCom tfcom, string brokerid, string account, string StockHistoryFile)
        {
            InitializeComponent();
            this.StockTable       = table;
            this.quotecom         = quotecom;
            this.tfcom            = tfcom;
            this.brokerid         = brokerid;
            this.account          = account;
            this.StockHistoryFile = StockHistoryFile;

            //建立下拉選單表格
            BuyModeTable.Columns.Add("BuyMode", typeof(string));
            BuyModeTable.Columns.Add("BuyMode_Text", typeof(string));
            BuyModeTable.Rows.Add("Auto", "自動");
            BuyModeTable.Rows.Add("Notify", "手動");
            BindingSource bindingBuyMode = new BindingSource();

            bindingBuyMode.DataSource = BuyModeTable;

            StatusTable.Columns.Add("Status", typeof(string));
            StatusTable.Columns.Add("Status_Text", typeof(string));
            StatusTable.Rows.Add("StandBy", "待命中");
            StatusTable.Rows.Add("WaitingBuySignal", "等待買入訊號");
            StatusTable.Rows.Add("WaitingBuy", "等待買入");
            StatusTable.Rows.Add("ConfirmBuyOrder", "確認委托買單");
            StatusTable.Rows.Add("ConfirmBuyMatch", "確認買單成交");
            StatusTable.Rows.Add("WaitingSellSignal", "等待賣出訊號");
            StatusTable.Rows.Add("WaitingSell", "等待賣出");
            StatusTable.Rows.Add("ConfirmSellOrder", "確認委托賣單");
            StatusTable.Rows.Add("ConfirmSellMatch", "確認賣單成交");
            StatusTable.Rows.Add("Stop", "中止流程");
            StatusTable.Rows.Add("Error", "錯誤");

            BindingSource bindingStatus = new BindingSource();

            bindingStatus.DataSource = StatusTable;

            StopLossModeTable.Columns.Add("StopLossMode", typeof(string));
            StopLossModeTable.Columns.Add("StopLossMode_Text", typeof(string));
            StopLossModeTable.Rows.Add("Auto", "自動");
            StopLossModeTable.Rows.Add("Manual", "手動");
            BindingSource bindingStopLossMode = new BindingSource();

            bindingStopLossMode.DataSource = StopLossModeTable;

            LockGainModeTable.Columns.Add("LockGainMode", typeof(string));
            LockGainModeTable.Columns.Add("LockGainMode_Text", typeof(string));
            LockGainModeTable.Rows.Add("Auto", "自動");
            LockGainModeTable.Rows.Add("Manual", "手動");
            BindingSource bindingLockGainMode = new BindingSource();

            bindingLockGainMode.DataSource = LockGainModeTable;

            //增加欄位名稱
            dgv_StockEditor.Columns.Add("StockID", "代號");
            dgv_StockEditor.Columns["StockID"].DataPropertyName = "StockID";
            dgv_StockEditor.Columns["StockID"].ReadOnly         = true;


            DataGridViewComboBoxColumn StatusCol = new DataGridViewComboBoxColumn();

            StatusCol.ValueMember      = "Status";
            StatusCol.DisplayMember    = "Status_Text";
            StatusCol.DataSource       = bindingStatus;
            StatusCol.Name             = "Status";
            StatusCol.DataPropertyName = "Status";
            StatusCol.HeaderText       = "狀態";
            StatusCol.ReadOnly         = true;
            StatusCol.DisplayStyle     = DataGridViewComboBoxDisplayStyle.Nothing;
            StatusCol.SortMode         = DataGridViewColumnSortMode.Automatic;
            dgv_StockEditor.Columns.Add(StatusCol);

            dgv_StockEditor.Columns.Add("AmountThreshold", "成交量門檻");
            dgv_StockEditor.Columns["AmountThreshold"].DataPropertyName = "AmountThreshold";
            dgv_StockEditor.Columns["AmountThreshold"].ToolTipText      = "前五分鐘成交量門檻";
            //dgv_StockEditor.Columns["AmountThreshold"].ReadOnly = true;



            DataGridViewComboBoxColumn BuyModeCol = new DataGridViewComboBoxColumn();

            BuyModeCol.ValueMember      = "BuyMode";
            BuyModeCol.DisplayMember    = "BuyMode_Text";
            BuyModeCol.DataSource       = bindingBuyMode;
            BuyModeCol.Name             = "BuyMode";
            BuyModeCol.DataPropertyName = "BuyMode";
            BuyModeCol.HeaderText       = "買入模式";
            //BuyModeCol.ReadOnly = true;
            BuyModeCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            BuyModeCol.SortMode     = DataGridViewColumnSortMode.Automatic;
            dgv_StockEditor.Columns.Add(BuyModeCol);

            DataGridViewComboBoxColumn StopLossModeCol = new DataGridViewComboBoxColumn();

            StopLossModeCol.ValueMember      = "StopLossMode";
            StopLossModeCol.DisplayMember    = "StopLossMode_Text";
            StopLossModeCol.DataSource       = bindingStopLossMode;
            StopLossModeCol.Name             = "StopLossMode";
            StopLossModeCol.DataPropertyName = "StopLossMode";
            StopLossModeCol.HeaderText       = "停損模式";
            //StopLossModeCol.ReadOnly = true;
            StopLossModeCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            StopLossModeCol.SortMode     = DataGridViewColumnSortMode.Automatic;
            dgv_StockEditor.Columns.Add(StopLossModeCol);

            DataGridViewComboBoxColumn LockGainModeCol = new DataGridViewComboBoxColumn();

            LockGainModeCol.ValueMember      = "LockGainMode";
            LockGainModeCol.DisplayMember    = "LockGainMode_Text";
            LockGainModeCol.DataSource       = bindingLockGainMode;
            LockGainModeCol.Name             = "LockGainMode";
            LockGainModeCol.DataPropertyName = "LockGainMode";
            LockGainModeCol.HeaderText       = "停利模式";
            //LockGainModeCol.ReadOnly = true;
            LockGainModeCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            LockGainModeCol.SortMode     = DataGridViewColumnSortMode.Automatic;
            dgv_StockEditor.Columns.Add(LockGainModeCol);

            //DataGridViewComboBoxColumn BuyQtyCol = new DataGridViewComboBoxColumn();
            //BuyQtyCol.Items.AddRange(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            //BuyQtyCol.Name = "BuyQty";
            //BuyQtyCol.DataPropertyName = "BuyQty";
            //BuyQtyCol.HeaderText = "設定買量";
            //dgv_StockList.Columns.Add(BuyQtyCol);
            dgv_StockEditor.Columns.Add("BuyQty", "設定買量");
            dgv_StockEditor.Columns["BuyQty"].DataPropertyName = "BuyQty";
            //dgv_StockEditor.Columns["BuyQty"].ReadOnly = true;


            BindingSource bs = new BindingSource();

            bs.DataSource = StockTable;
            dgv_StockEditor.DataSource = bs;

            ////隱藏不顯示欄位
            dgv_StockEditor.Columns["TradeBot"].Visible     = false;
            dgv_StockEditor.Columns["BuyAvgPrice"].Visible  = false;
            dgv_StockEditor.Columns["MatchBuyQty"].Visible  = false;
            dgv_StockEditor.Columns["SellAvgPrice"].Visible = false;
            dgv_StockEditor.Columns["MatchSellQty"].Visible = false;
            dgv_StockEditor.Columns["ROI"].Visible          = false;
            dgv_StockEditor.Columns["ClosePrice"].Visible   = false;
            dgv_StockEditor.Columns["OpenPrice"].Visible    = false;
            dgv_StockEditor.Columns["MatchTime"].Visible    = false;
            dgv_StockEditor.Columns["MatchPrice"].Visible   = false;
            dgv_StockEditor.Columns["MatchQty"].Visible     = false;
            dgv_StockEditor.Columns["TotalQty"].Visible     = false;
            dgv_StockEditor.Columns["AH"].Visible           = false;
            dgv_StockEditor.Columns["NH"].Visible           = false;
            dgv_StockEditor.Columns["NL"].Visible           = false;
            dgv_StockEditor.Columns["AL"].Visible           = false;

            //設定下拉選單預設值
            cb_BuyMode.SelectedIndex      = 0;
            cb_StopLossMode.SelectedIndex = 0;
            cb_LockGainMode.SelectedIndex = 0;
        }
Exemplo n.º 30
0
    public void Form1_Load(object sender, EventArgs e)
    {
        DataGridViewCheckBoxColumn column0 =
            new DataGridViewCheckBoxColumn();
        DataGridViewDisableButtonColumn column1 =
            new DataGridViewDisableButtonColumn();

        DataGridViewComboBoxColumn column2 = new DataGridViewComboBoxColumn();

        column2.Items.Add("test1");
        column2.Items.Add("test2");

        column0.Name = "CheckBoxes";
        column1.Name = "Buttons";
        column2.Name = "Combobox";

        dataGridView1.Columns.Add(column0);
        dataGridView1.Columns.Add(column1);
        dataGridView1.Columns.Add(column2);
        dataGridView1.RowCount           = /*8*/ 1;
        dataGridView1.AutoSize           = true;
        dataGridView1.AllowUserToAddRows = false;
        dataGridView1.ColumnHeadersDefaultCellStyle.Alignment =
            DataGridViewContentAlignment.MiddleCenter;

        // Set the text for each button.
        int row = dataGridView1.RowCount;

        for (int i = 0; i < dataGridView1.RowCount; i++)
        {
            dataGridView1.Rows[i].Cells["Buttons"].Value =
                "Button " + i.ToString();

            dataGridView1.Rows[i].Cells["Combobox"].Value = "test2";
        }

        this.panel1.Controls.Clear();
        this.panel1.Controls.Add(dataGridView1);
        //dataGridView1.AutoGenerateColumns = true;
        //var source = new BindingSource();

        ////使用List<>泛型集合填充DataGridView
        //List<Student> students = new List<Student>();
        //Student hat = new Student(true, "12", "Male");
        //Student peter = new Student(false, "14", "Male");
        //Student dell = new Student(true, "16", "Male");
        //Student anne = new Student(false, "19", "Female");
        //students.Add(hat);
        //students.Add(peter);
        //students.Add(dell);
        //students.Add(anne);

        //source.DataSource = students;

        //this.dataGridView1.DataSource = source;
        //this.dataGridView1.Refresh();

        //dataGridView1.CellValueChanged +=
        //    new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
        //dataGridView1.CurrentCellDirtyStateChanged +=
        //    new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);
        //dataGridView1.CellClick +=
        //    new DataGridViewCellEventHandler(dataGridView1_CellClick);

        //this.Controls.Add(dataGridView1);
    }
 ///<summary>
 /// Constructor for <see cref="DataGridViewComboBoxColumnVWG"/>
 ///</summary>
 ///<param name="dataGridViewComboBoxColumn"></param>
 public DataGridViewComboBoxColumnVWG(DataGridViewComboBoxColumn dataGridViewComboBoxColumn)
     : base(dataGridViewComboBoxColumn)
 {
     _dataGridViewComboBoxColumn = dataGridViewComboBoxColumn;
 }
Exemplo n.º 32
0
    private void btnChanges_Click(object sender, EventArgs e)
    {
        string cad;

        try
        {
            String Action = "";
            if (cbAction.SelectedIndex >= 0)
                Action = cbAction.Text.Substring(0, 2);

            switch (Action)
            {
                case " 0":   // MOD "Keyboard"
                    cad = ChangeCase(Products[0].Name);
                    if (cad.EndsWith("*"))
                        cad = cad.Substring(0, cad.Length - 1);
                    else
                        cad = cad + "*";

                    // NOTE!!: A modification that only changes the case of the letters will be ignored by comboBox controls. Is its normal behaviour.
                    // Thats why "*" is added or removed.

                    Products[0].Name = cad;
                    break;

                case " 1":   // MOD "Jane Wilson" & "Bill Smith"
                    cad = ChangeCase(Customers[0].Name);
                    Customers[0].Name = cad;
                    cad = ChangeCase(Customers[1].Name);
                    Customers[1].Name = cad;
                    break;

                case " 2":   // MOD "Keyboard" & "Mose"
                    cad = ChangeCase(Products[0].Name);
                    Products[0].Name = cad;
                    cad = ChangeCase(Products[1].Name);
                    Products[1].Name = cad;
                    break;

                case " 3":   // INC OrderDate: Order-1 & Order-2
                    Orders[0].OrderDate = Orders[0].OrderDate.AddDays(1);
                    Orders[1].OrderDate = Orders[1].OrderDate.AddDays(1);
                    break;

                case " 4":   // Order-1.OrderLines[1].Product <- Order-1.OrderLines[0].Product
                    Orders[0].OrderLines[1].Product = Orders[0].OrderLines[0].Product;
                    break;

                case " 5":   // INC OrderLines[0].Quantity:  Order-1 & Order-2
                    Orders[0].OrderLines[0].Quantity += 1;
                    Orders[1].OrderLines[0].Quantity += 1;
                    break;

                case " 6":   // INC Customer.Age  <Jane Wilson> & <Bill Smith>
                    Customers[0].Age += 1;
                    Customers[1].Age += 1;
                    break;

                case " 7":   // INC Product.UnitPrice: <Keyboard> & <Mouse>
                    Products[0].UnitPrice += 10;
                    Products[1].UnitPrice += 10;
                    break;

                case " 8":   // MOD <Keyboard>.ChangeMultiple (Property=Nothing)
                    Products[0].ChangeMultiple();
                    break;

                case " 9":   // Remove <Samantha Brown>
                    Customers.RemoveAt(2);
                    break;

                case "10":   // Remove <LapTop>
                    Products.RemoveAt(4);
                    break;

                case "11": // Delete All
                    Orders.Clear();
                    Customers.Clear();
                    Products.Clear();
                    OtherItems.Clear();
                    SimpleClasses.Clear();

                    // As Orders and OtherItems don't implement IBindingList but only IList, deleting these lists will raise
                    // an error on the DataGridView binded to the objects BindingSource on trying to refresh their cells, because
                    // BindingSource objects are not aware of the other objects deletion and so they don't inform to the consumers
                    // (DataGridView in this case)
                    // Also, if we make DataSource = null in the BindingSource controls will cause the same error because they will trigger
                    // the method MyBase.ResetBindings(True) and that will raise ListChanged, forcing the DataGridView to refresh their
                    // content
                    // ==> We must execute .ResetBindings(false) just after the .Clear() previous

                    productsBindingSource.DataSource = typeof(Product);
                    customersBindingSource.DataSource = typeof(Customer);

                    ordersBindingSource.ResetBindings(false);
                    otherItemsBindingSource.ResetBindings(false);

                    dataGridView1.AutoGenerateColumns = false;

                    orderlinesBindingSource.DataSource = null;
                    ordersBindingSource.DataSource = null;
                    otherItemsBindingSource.DataSource = null;
                    simpleClassesBindingSource.DataSource = null;
                    break;

                case "12":   // BindingSourceS.Dispose
                    orderlinesBindingSource.Dispose();
                    ordersBindingSource.Dispose();
                    productsBindingSource.Dispose();
                    customersBindingSource.Dispose();
                    otherItemsBindingSource.Dispose();
                    simpleClassesBindingSource.Dispose();
                    break;

                case "13":  // Add New Order (4: <Jane Wilson>)
                    Order o = new Order(4, DateTime.Now, Customers[0]);
                    o.OrderLines.Add(new OrderLine(Products[1], 4));
                    o.OrderLines.Add(new OrderLine(Products[4], 5));
                    Orders.Add(o);

                    _Objects.Add(new WeakReference(o));
                    ordersBindingSource.ResetBindings(false);     // Pues el origen no es IBindingList
                    break;

                case "14":  // Remove New Order (4: <Jane Wilson>)
                    Orders.RemoveAt(3);
                    ordersBindingSource.ResetBindings(false);     // Pues el origen no es IBindingList
                    break;

                case "24":  // INSERT New Order (4: <Jane Wilson>) at position 1
                    o = new Order(4, DateTime.Now, Customers[0]);
                    o.OrderLines.Add(new OrderLine(Products[1], 4));
                    o.OrderLines.Add(new OrderLine(Products[4], 5));
                    Orders.Insert(1, o);

                    _Objects.Add(new WeakReference(o));
                    ordersBindingSource.ResetBindings(false);     // Pues el origen no es IBindingList
                    break;

                case "15":  // MOD ordersBindingSource.BindableNestedProperties: A
                    ordersBindingSource.BindableNestedProperties = new string[] {
                            "Customer.Name",
                            "Customer.BillingAddress.StreetAddress",
                            "Customer.BillingAddress.City",
                            "DeliveryAddress.StreetAddress",
                            "DeliveryAddress.City",
                            "Customer.FavoriteProduct.Name"};

                    //DataGridViewColumn c = new DataGridViewTextBoxColumn();
                    //c.DataPropertyName = "Customer_FavoriteProduct_Name";
                    //c.HeaderText = "Customer.FavoriteProduct.Name";
                    //c.Name = "customerFavoriteProductNameDataGridViewTextBoxColumn";
                    //dataGridView1.Columns.Add(c);
                    break;

                case "16":  // MOD ordersBindingSource.BindableNestedProperties: B
                    ordersBindingSource.BindableNestedProperties = new string[] {
                            "Customer.Name",
                            "Customer.BillingAddress.StreetAddress",
                            "Customer.BillingAddress.City",
                            "DeliveryAddress.StreetAddress",
                            "DeliveryAddress.City"};

                    //c = dataGridView1.Columns[dataGridView1.Columns.Count-1];
                    //if (c.DataPropertyName == "Customer_FavoriteProduct_Name")
                    //    dataGridView1.Columns.RemoveAt(dataGridView1.Columns.Count - 1);
                    break;

                case "23":  // MOD ordersBindingSource.BindableNestedProperties: C
                    ordersBindingSource.BindableNestedProperties = new string[] {
                            "Customer.Name",
                            "Customer.BillingAddress.StreetAddress",
                            "Customer.BillingAddress.City",
                            "DeliveryAddress.StreetAddress",
                            "DeliveryAddress.City",
                            "Customer.FavoriteProduct.NonExistentProperty"};
                    break;

                case "17":   // MOD orderlinesBindingSource.BindableNestedProperties: A
                    orderlinesBindingSource.BindableNestedProperties = new string[] {
                            "Product.ProductId",
                            "Product.UnitPrice",
                            "Product.Name",
                            "Product.Type"};

                    // I have set: dataGridView2.AutoGenerateColumns = false;

                    DataGridViewComboBoxColumn productType = new DataGridViewComboBoxColumn();
                    productType.DataSource = new EnumeratedValueCollection<ProductType>();
                    productType.ValueMember = "Value";
                    productType.DisplayMember = "Description";
                    productType.DataPropertyName = "Product_Type";
                    productType.HeaderText = "Product.Type";
                    dataGridView2.Columns.Add(productType);
                    break;

                case "20":  // MOD Orders[0].OrderLines[0].Details[0].NotShownProperty
                    Orders[0].OrderLines[0].Details[0].NotShownProperty += 10;
                    break;

                case "21":   // Orders[0].OrderLines = Orders[0].OrderLines;
                    Orders[0].OrderLines = Orders[0].OrderLines;
                    break;

                case "22":   // Orders[0].OrderLines = Orders[1].OrderLines;
                    Orders[0].OrderLines = Orders[1].OrderLines;
                    break;

                case "25":   // MOD orderlinesBindingSource.BindableNestedProperties: B
                    orderlinesBindingSource.BindableNestedProperties = new string[] {
                            "Product.ProductId",
                            "Product.UnitPrice",
                            "Product.Name"};
                    break;

                case "26":   // MOD orderlinesBindingSource.BindableNestedProperties: C
                    orderlinesBindingSource.BindableNestedProperties = null;
                    break;

                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }