/// <summary> /// 线程处理一个线程最多处理10行数据 /// </summary> /// <param name="obj"></param> private void InsertGridRow(object obj) { int _firstRowIndex = (int)obj; for (int Index = _firstRowIndex; Index < _firstRowIndex + 10; Index++) { lock (Locked) { if (Index >= Dgv_Data.Rows.Count) { AsyncOpDone.Set(); return; } CLDC_DataCore.Model.DnbModel.DnbInfo.MeterBasicInfo MeterInfo = _DnbInfo.MeterGroup[Index]; Dgv_Data.Rows[Index].Cells[0].Value = MeterInfo.ToString(); Dgv_Data.Rows[Index].Cells[4] = (DataGridViewComboBoxCell)_ProtocolNameCol.Clone(); if (MeterInfo.YaoJianYn) { Dgv_Data.Rows[Index].Cells[1].Value = MeterInfo.Mb_ChrTxm; Dgv_Data.Rows[Index].Cells[2].Value = MeterInfo.Mb_ChrJlbh; Dgv_Data.Rows[Index].Cells[3].Value = MeterInfo.Mb_ChrCcbh; if (MeterInfo.DgnProtocol.Loading) { Dgv_Data.Rows[Index].Cells[4].Value = MeterInfo.DgnProtocol.ProtocolName; Dgv_Data.Rows[Index].Cells[5].Value = MeterInfo.DgnProtocol.Setting; Dgv_Data.Rows[Index].Cells[6].Value = MeterInfo.Mb_chrAddr; Dgv_Data.Rows[Index].Cells[7].Value = MeterInfo.DgnProtocol.WritePassword + MeterInfo.DgnProtocol.WriteClass; Dgv_Data.Rows[Index].Cells[7].Tag = Dgv_Data.Rows[Index].Cells[7].Value; Dgv_Data.Rows[Index].Cells[8].Value = MeterInfo.DgnProtocol.ClearDemandPassword + MeterInfo.DgnProtocol.ClearDemandClass; Dgv_Data.Rows[Index].Cells[8].Tag = Dgv_Data.Rows[Index].Cells[8].Value; Dgv_Data.Rows[Index].Cells[9].Value = MeterInfo.DgnProtocol.ClearDLPassword + MeterInfo.DgnProtocol.ClearDLClass; Dgv_Data.Rows[Index].Cells[9].Tag = Dgv_Data.Rows[Index].Cells[9].Value; } if (Index % 2 == 0) //设置单双行背景颜色 { Dgv_Data.Rows[Index].DefaultCellStyle.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Normal; } else { Dgv_Data.Rows[Index].DefaultCellStyle.BackColor = CLDC_DataCore.Const.Variable.Color_Grid_Alter; } } else //设置不检表的行背景颜色 { Dgv_Data.Rows[Index].DefaultCellStyle.BackColor = Color.FromName(System.Drawing.KnownColor.Control.ToString()); Dgv_Data.Rows[Index].ReadOnly = true; } } } AsyncOpDone.Set(); }
private void ShowJournal() { //инициализация студентов InitStudents(); journalGrid.AllowUserToAddRows = true; journalGrid.ColumnCount = 2; journalGrid.RowCount = 1; journalGrid.RowHeadersVisible = false; //отображение таблицы DateTime date = dateTimePicker1.Value; for (int i = 0; i < 6; i++) { journalGrid.Columns.Add($"{date.ToShortDateString()}", date.ToShortDateString()); journalGrid.Columns[journalGrid.ColumnCount - 1].Width = 75; date = date.AddDays(1); } DataGridViewComboBoxCell markBox = new DataGridViewComboBoxCell(); markBox.Items.AddRange("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Н", "none"); foreach (var item in _students) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell idCell = new DataGridViewTextBoxCell(); idCell.Value = item.Id; DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell(); nameCell.Value = item.Name; row.Cells.AddRange(idCell, nameCell); for (int i = 0; i < 6; i++) { var tmpCell = (DataGridViewComboBoxCell)markBox.Clone(); row.Cells.Add(tmpCell); } foreach (var mark in item.Marks) { if (journalGrid.Columns.Contains(mark.Date.ToShortDateString())) { row.Cells[(mark.Date - dateTimePicker1.Value).Days + 2].Value = mark.Value.ToString(); } } foreach (var miss in item.Misses) { if (journalGrid.Columns.Contains(miss.date.ToShortDateString())) { row.Cells[(miss.date - dateTimePicker1.Value).Days + 2].Value = "Н"; } } journalGrid.Rows.Add(row); } journalGrid.AllowUserToAddRows = false; }
private void listBoxGroup1_SelectedIndexChanged(object sender, System.EventArgs e) { dataGridView.Rows.Clear(); if (listBoxGroup1.SelectedIndices.Count == 0) { return; } listBoxGroup2.ClearSelected(); var obj = amaFile.Group1[listBoxGroup1.SelectedIndex]; var G1List = new string[amaFile.Group1.Count + 1]; G1List[0] = "(None)"; for (int i = 0; i < amaFile.Group1.Count; i++) { G1List[i + 1] = amaFile.Group1[i].Name; } var comboboxG1 = new DataGridViewComboBoxCell(); comboboxG1.Items.AddRange(G1List); comboboxG1.Value = "(None)"; var G2List = new string[amaFile.Group2.Count + 1]; G2List[0] = "(None)"; for (int i = 0; i < amaFile.Group2.Count; i++) { G2List[i + 1] = amaFile.Group2[i].Name; } var comboboxG2 = new DataGridViewComboBoxCell(); comboboxG2.Items.AddRange(G2List); comboboxG2.Value = "(None)"; dataGridView.Rows.Add("Group 1 Child 0", ""); dataGridView[1, 0] = (DataGridViewCell)comboboxG1.Clone(); if (obj.G1Child0 != null) { dataGridView[1, 0].Value = G1List[Array.IndexOf(G1List, obj.G1Child0.Name)]; } dataGridView.Rows.Add("Group 1 Child 1", ""); dataGridView[1, 1] = (DataGridViewCell)comboboxG1.Clone(); if (obj.G1Child1 != null) { dataGridView[1, 1].Value = G1List[Array.IndexOf(G1List, obj.G1Child1.Name)]; } dataGridView.Rows.Add("Group 1 Parent", ""); dataGridView[1, 2] = (DataGridViewCell)comboboxG1.Clone(); if (obj.Parent != null) { dataGridView[1, 2].Value = G1List[Array.IndexOf(G1List, obj.Parent.Name)]; } dataGridView.Rows.Add("Group 2 Child 0", ""); dataGridView[1, 3] = (DataGridViewCell)comboboxG2.Clone(); if (obj.G2Child0 != null) { dataGridView[1, 3].Value = G2List[Array.IndexOf(G2List, obj.G2Child0.Name)]; } }