private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e) { Bitmap bm = new Bitmap(this.DataGridView1.Width, this.DataGridView1.Height); DataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.DataGridView1.Width, this.DataGridView1.Height)); e.Graphics.DrawImage(bm, 0, 0); }
private void ColorPickEdit1_EditValueChanged(object sender, EventArgs e) { if (ChangeColorDirext == false) { Button2.BackColor = ColorPickEdit1.Color; } else { if (DataGridView1.Rows.Count > 0) { DataGridView1.CurrentRow.Cells[11].Value = ColorPickEdit1.Color.ToArgb().ToString(); DataGridView1.CurrentRow.Cells[12].Style.BackColor = ColorPickEdit1.Color; Panel4.Controls.Find(DataGridView1.CurrentRow.Cells[1].Value.ToString(), true)[0].BackColor = ColorPickEdit1.Color; ChangeColorDirext = false; DataGridView1.ClearSelection(); txtDescripcion.Text = "Mesa " + (NumControlsInteger() + 1); ColorPickEdit1.Color = SystemColors.Control; txtLocacion.Clear(); txtLocacionY.Clear(); txtLocacionX.Clear(); txtDescripcion.Focus(); txtDescripcion.SelectAll(); txtTag.Clear(); txtTamañoHeight.Text = "70"; txtTamañoWidth.Text = "120"; txtName.Clear(); DataGridView1.ClearSelection(); } } }
private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (DataGridView1.IsCurrentCellDirty) { DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit); } }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Bitmap bmp = new Bitmap(DataGridView1.Size.Width + 10, DataGridView1.Size.Height + 10); DataGridView1.DrawToBitmap(bmp, DataGridView1.Bounds); e.Graphics.DrawImage(bmp, 0, 0); }
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) { DataTable dt1 = controllerObj.GetAllInfoOfInternshipByName(comboBox1.SelectedValue.ToString()); DataGridView1.DataSource = dt1; DataGridView1.Refresh(); }
public void mark(TextBox sender, TextBox tb) { int count = 0; try { string[] words = tb.Text.Split(','); for (int i = 0; i < (DataGridView1.RowCount - 1); i++) { if (DataGridView1.Rows[i].Cells[columnSelect].Value is object) { foreach (string wor in words) { if (DataGridView1.Rows[i].Cells[columnSelect].Value.ToString().IndexOf(wor) >= 0) { DataGridView1.Rows[i].Cells[columnSelect].Style.BackColor = sender.BackColor; count += 1; continue; } } } } sender.Text = string.Format("{0}", count); DataGridView1.Refresh(); } catch (Exception) { // dummy } }
private void RetrieveDialogType_Load(object sender, EventArgs e) { SM = new StudyMover.StudyMover(); dtpDateFrom.CustomFormat = "dd/MM/yyyy"; dtpDateTo.CustomFormat = "dd/MM/yyyy"; dtpDateFrom.Value = DateTime.Now.Date; dtpDateTo.Value = DateTime.Now.Date; TeleRadPush.modMain.Retreived = false; DataGridView1.Refresh(); this.Cursor = Cursors.WaitCursor; this.PatientStudyViewTableAdapter.Fill(this.PatientStudyView.PatientStudyView); //Me.StudyViewTableAdapter.Fill(Me.DicomServerDBDataSet1.StudyView) //OptionsBox = New OptionsBoxType //If UType = 2 Then // os = New frmOS //Else // sp = New frmSP //End If //NotesReports_Images(); this.Cursor = Cursors.Default; WoN_WoR = Color.White; WN_WoR = Color.LightPink; WN_WR = Color.PowderBlue; GridDesign(); }
private void Form4_Load(object sender, EventArgs e) { this.BackColor = System.Drawing.SystemColors.ControlLightLight; // Button1.Visible = false; //Button2.Visible = False DataGridView1.Refresh(); DataGridView1.AllowUserToAddRows = false; //可以不显示最后一行空 DataGridView1.ReadOnly = true; //不允许用户更改数据 // DataGridView1.ReadOnly = false; DataGridView1.RowsDefaultCellStyle.BackColor = Color.White; //.AntiqueWhite; DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue; DataGridView1.DataSource = ds.Tables[0]; // DataGridView1.AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode.ColumnHeader; // DataGridView1.AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode.AllCells; // for (int i=0;i<DataGridView1.Columns.Count;i++) // { // DataGridView1.Columns[i].Width = 92; // } // DataGridView1.DataSource = ds;//.Tables[1]; // DataGridView1.DataBindings(); Type dgvType = DataGridView1.GetType(); System.Reflection.PropertyInfo pi = null; pi = dgvType.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); //pi.SetValue(dgvType, setting, Nothing) pi.SetValue(DataGridView1, true, null); this.WindowState = FormWindowState.Maximized; }
private void button2_Click(object sender, EventArgs e) { this.clickCounter++; if (this.clickCounter < 4) { Int32 selectedCellCount = DataGridView1.GetCellCount(DataGridViewElementStates.Selected); if (selectedCellCount > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < selectedCellCount; i++) { sb.Append("Row: "); sb.Append(DataGridView1.SelectedCells[i].RowIndex .ToString()); sb.Append(", Column: "); sb.Append(DataGridView1.SelectedCells[i].ColumnIndex .ToString()); sb.Append(Environment.NewLine); DataGridView1.Rows[DataGridView1.SelectedCells[i].RowIndex].Cells[DataGridView1.SelectedCells[i].ColumnIndex].Value = map[DataGridView1.SelectedCells[i].RowIndex, DataGridView1.SelectedCells[i].ColumnIndex]; MessageBox.Show(DataGridView1.Rows[DataGridView1.SelectedCells[i].RowIndex].Cells[DataGridView1.SelectedCells[i].ColumnIndex].Value.ToString()); } } } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt1 = controllerObj.GetInfoOfAProjectTeamByNumber(comboBox1.SelectedValue.ToString()); DataGridView1.DataSource = dt1; DataGridView1.Refresh(); }
private void SQL_Click(object sender, EventArgs e) { //OleDbConnection conn = new OleDbConnection(); //conn.ConnectionString = gConnect; //conn.Open(); DataTable dt = functions.ExecuteSQLQuery(TextBox1.Text); DataGridView1.ClearSelection(); DataGridView1.DataSource = dt; // DataGridView1.ClearSelection(); // DataGridView1.DataSource = ds; // DataGridView1.DataMember = "PEL"; // //GridView1.Columns(STHLHTOY_ID).Width = 0 // // DataGridView1.Columns(STHLHTOY_ID).Visible = False //} catch (SqlException ex) { // Interaction.MsgBox(ex.ToString); //} finally { // // Close connection // conn.Close(); }
private void button2_Click(object sender, EventArgs e) { var results = ( from dataRow in DataGridView1 .GetRowsChecked(checkBoxColumnName) .GroupBy((item) => 3 > 0) .Select( groupRow => new Item { Value1Sum = groupRow.Sum((row) => row.Field <int>("Value1")), Value2Sum = groupRow.Sum((row) => row.Field <int>("Value2")) } ) select dataRow) .FirstOrDefault(); if (results != null) { Console.WriteLine("Value1: {0} Value2: {1}", results.Value1Sum, results.Value2Sum); } else { Console.WriteLine("Nothing checked"); } }
private void toolStripButton1_Click(object sender, EventArgs e) { upDateDataGridView(); achelp = new AccessHelper(); if (cbbxMode.Text == "") { MessageBox.Show("Please select the query mode "); return; } else { string strCbxCondition = ""; if (cbbxMode.Text == "Dates") { strCbxCondition = "\"" + cbxCondition.Text + "\""; //strSelectSql = "SELECT * FROM DeviceMsg where (" + cbbxMode.Text + "=" + cbxCondition.Text + ")"; } else { strCbxCondition = "'" + cbxCondition.Text + "'"; } string strSelectSql = "SELECT IpAddress ,DeviceNum,Dates,Times,OrderNum,CarriageNum,ArtNo,SetWeight,LoadedWeight,TotalAmount FROM DeviceMsg where (" + cbbxMode.Text + "=" + strCbxCondition + ")"; DataTable dt = new System.Data.DataTable(); dt = achelp.GetDataTableFromDB(strSelectSql); DataGridView1.DataSource = dt; DataGridView1.Columns[DataGridView1.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } }
private void Form1_Load(object sender, EventArgs e) { DataOperations DataOps = new DataOperations(); bsCustomers.DataSource = DataOps.GetCustomers(); DataGridView1.DataSource = bsCustomers; DataGridView1.ExpandColumns(); }
private void Form4_FormClosing(object sender, FormClosingEventArgs e) { DataGridView1.DataSource = null; DataGridView1.Dispose(); ds.Tables[0].Clear(); ds.Clear(); ds.Dispose(); GC.Collect(); }
void TxtOderCsvToolStripMenuItemClick(object sender, EventArgs e) { if (OpenFileDialog1.ShowDialog() != DialogResult.OK) { return; } loadCsv(OpenFileDialog1.FileName); DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); }
private void Form1_Load(object sender, EventArgs e) { DataOperations DataOps = new DataOperations(); bsCustomers.DataSource = DataOps.GetCustomers(); DataGridView1.DataSource = bsCustomers; DataGridView1.ExpandColumns(); bsCustomers.Sort = "CompanyName"; ActiveControl = txtCompanyName; }
/// <summary> /// Provides one click access to custom columns. /// This may or may not be something you want but wanted to /// show how it can be done /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { if (DataGridView1[e.ColumnIndex, e.RowIndex].EditType != null) { if (DataGridView1.IsCalendarCell(e) || DataGridView1.IsTimeCell(e)) { SendKeys.Send("{F2}"); } } }
private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Bitmap objBmp = new Bitmap(this.DataGridView1.Width, this.DataGridView1.Height); DataGridView1.DrawToBitmap(objBmp, new Rectangle(0, 0, this.DataGridView1.Width, this.DataGridView1.Height)); e.Graphics.DrawImage(objBmp, 120, 100); e.Graphics.DrawString(Label1.Text, new Font("Verdana", 30, FontStyle.Bold), Brushes.Black, new Point(300, 30)); }
private void btnModificar_Click(object sender, EventArgs e) { if (!(string.IsNullOrEmpty(Label7.Text))) { if (Panel4.Controls.Count > 0) { foreach (DataGridViewRow Row in DataGridView1.Rows) { if (Row.Cells[1].Value.ToString() == Label7.Text) { if (Convert.ToBoolean(Row.Cells[15].Value) == true) { MessageBox.Show(this, "La " + Convert.ToString(Row.Cells[2].Value) + " está incluído para mover en grupos." + Environment.NewLine + Environment.NewLine + "Por favor deseleccione esta opción para modificarla.", "Mesa incluída", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { if (Row.Cells[0].Value == null) { IDMesaM = ""; DataGridView1.Rows.Remove(Row); } else { IDMesaM = Convert.ToString(Row.Cells[0].Value.ToString()); cbxTipoMesa.Text = Row.Cells[14].Value.ToString(); DataGridView1.Rows.Remove(Row); } } } } txtDescripcion.Text = this.Controls.Find(Label7.Text, true)[0].Text; txtLocacion.Text = this.Controls.Find(Label7.Text, true)[0].Location.ToString(); txtLocacionX.Text = this.Controls.Find(Label7.Text, true)[0].Location.X.ToString(); txtLocacionY.Text = this.Controls.Find(Label7.Text, true)[0].Location.Y.ToString(); txtTamañoHeight.Text = this.Controls.Find(Label7.Text, true)[0].Size.Height.ToString(); txtTamañoWidth.Text = this.Controls.Find(Label7.Text, true)[0].Size.Width.ToString(); TrackBar1.Value = this.Controls.Find(Label7.Text, true)[0].Size.Width; TrackBar2.Value = this.Controls.Find(Label7.Text, true)[0].Size.Height; ColorPickEdit1.Color = this.Controls.Find(Label7.Text, true)[0].BackColor; txtName.Text = this.Controls.Find(Label7.Text, true)[0].Name; txtTag.Text = Convert.ToString(this.Controls.Find(Label7.Text, true)[0].Tag); Button2.BackColor = this.Controls.Find(Label7.Text, true)[0].BackColor; Panel4.Controls.Remove(this.Controls.Find(Label7.Text, true)[0]); Label7.Text = ""; Label5.Text = "Cant. de Mesas: " + NumControlsInteger(); DataGridView1.ClearSelection(); } } }
public int GridDesign() { int lb2 = 0; int lb3 = 0; int lb4 = 0; lb2 = 0; lb3 = 0; lb4 = 0; label2.Text = "Without Notes && Reports"; label3.Text = "Notes without Reports"; label4.Text = "With Notes && Reports"; DataGridViewCellStyle m_SelectedStyle = default(DataGridViewCellStyle); DataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.DarkGray; DataGridView1.DefaultCellStyle.SelectionBackColor = Color.DarkGray; DataGridView1.RowHeadersDefaultCellStyle.SelectionForeColor = Color.White; DataGridView1.DefaultCellStyle.SelectionForeColor = Color.White; for (i = 0; i <= DataGridView1.RowCount - 1; i++) { if (DataGridView1.Rows[i].Cells[13].Value == DBNull.Value || DataGridView1.Rows[i].Cells[14].Value == DBNull.Value) { return(0); } ; if (Convert.ToBoolean(DataGridView1.Rows[i].Cells[13].Value) == false & Convert.ToBoolean(DataGridView1.Rows[i].Cells[14].Value) == false) { m_SelectedStyle = new DataGridViewCellStyle(); m_SelectedStyle.BackColor = WoN_WoR; DataGridView1.Rows[i].DefaultCellStyle = m_SelectedStyle; lb2 = lb2 + 1; } if (Convert.ToBoolean(DataGridView1.Rows[i].Cells[13].Value) == true & Convert.ToBoolean(DataGridView1.Rows[i].Cells[14].Value) == false) { m_SelectedStyle = new DataGridViewCellStyle(); m_SelectedStyle.BackColor = WN_WoR; DataGridView1.Rows[i].DefaultCellStyle = m_SelectedStyle; lb3 = lb3 + 1; } if (Convert.ToBoolean(DataGridView1.Rows[i].Cells[13].Value) == true & Convert.ToBoolean(DataGridView1.Rows[i].Cells[14].Value) == true) { m_SelectedStyle = new DataGridViewCellStyle(); m_SelectedStyle.BackColor = WN_WR; DataGridView1.Rows[i].DefaultCellStyle = m_SelectedStyle; lb4 = lb4 + 1; } } label2.Text = label2.Text + ": " + lb2 + " Records"; label3.Text = label3.Text + ": " + lb3 + " Records"; label4.Text = label4.Text + ": " + lb4 + " Records"; DataGridView1.Refresh(); return(1); }
private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (DataGridView1.CurrentCell is DataGridViewCheckBoxCell) { if (DataGridView1.Columns[DataGridView1.CurrentCell.ColumnIndex].Name == "AvailableColumn") { DataGridView1.EndEdit(); bool Checked = Convert.ToBoolean(DataGridView1.CurrentCell.Value); } } }
private void ResortDataGridView() { if (DataGridView1.SortOrder != SortOrder.None && DataGridView1.SortedColumn != null) { System.ComponentModel.ListSortDirection Direction = System.ComponentModel.ListSortDirection.Ascending; if (DataGridView1.SortOrder == SortOrder.Descending) { Direction = System.ComponentModel.ListSortDirection.Descending; } DataGridView1.Sort(DataGridView1.SortedColumn, Direction); } }
private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (sortAscending) { DataGridView1.Sort(DataGridView1.Columns[e.ColumnIndex], System.ComponentModel.ListSortDirection.Ascending); } else { DataGridView1.Sort(DataGridView1.Columns[e.ColumnIndex], System.ComponentModel.ListSortDirection.Descending); } sortAscending = !sortAscending; }
private void pictureBox1_Click(object sender, EventArgs e) { Label6.Hide(); Panel1.Size = new Size(45, 727); pictureBox1.Hide(); Button1.Hide(); Button2.Hide(); Button3.Hide(); Button4.Hide(); PictureBox2.Show(); DataGridView1.Hide(); }
private void btnParseTextFiles_Click(object sender, EventArgs e) { using (TextFieldParser myReader = new TextFieldParser("test.txt")) { // 定义三种格式之各栏的宽度与分隔字符。 int[] FirstFormat = { 5, 10, -1 }; int[] SecondFormat = { 6, 10, 17, -1 }; string[] ThirdFormat = { "," }; this.DataGridView1.Rows.Clear(); this.DataGridView2.Rows.Clear(); this.DataGridView3.Rows.Clear(); string[] CurrentRow; while (!myReader.EndOfData) { try { string RowType = myReader.PeekChars(2); switch (RowType) { case "CK": myReader.TextFieldType = FieldType.FixedWidth; myReader.FieldWidths = FirstFormat; // 或是 myReader.SetFieldWidths(FirstFormat); CurrentRow = myReader.ReadFields(); this.DataGridView1.Rows.Add(CurrentRow); break; case "PB": myReader.TextFieldType = FieldType.FixedWidth; myReader.FieldWidths = SecondFormat; // 或是 myReader.SetFieldWidths(SecondFormat); CurrentRow = myReader.ReadFields(); this.DataGridView2.Rows.Add(CurrentRow); break; case "SP": myReader.TextFieldType = FieldType.Delimited; myReader.Delimiters = ThirdFormat; // 或是 myReader.SetDelimiters(ThirdFormat); CurrentRow = myReader.ReadFields(); this.DataGridView3.Rows.Add(CurrentRow); break; } } catch (MalformedLineException ex) { MessageBox.Show("行 " + ex.Message + " 是无效的。略过。"); } } // 排序各个 DataGridView 控件的内容。 DataGridView1.Sort(DataGridView1.Columns[0], System.ComponentModel.ListSortDirection.Ascending); DataGridView2.Sort(DataGridView2.Columns[0], System.ComponentModel.ListSortDirection.Ascending); DataGridView3.Sort(DataGridView3.Columns[0], System.ComponentModel.ListSortDirection.Ascending); } }
public void btnupdate_Click(System.Object sender, System.EventArgs e) { con.Open(); sql = "UPDATE tblinfo SET account_no=\'" + txtAcctNo.Text + "\',pin_code=\'" + txtPincode.Text + "\',Firstname=\'" + txtfnme.Text + "\',Lastname=\'" + txtlnme.Text + "\',Address=\'" + txtaddr.Text + "\',Contact_no=\'" + txtcontact.Text + "\',Gender=\'" + cbGender.Text + "\'where Firstname=\'" + lblhide.Text + "\'"; cmd.CommandText = sql; cmd.Connection = con; cmd.ExecuteNonQuery(); cmd.Dispose(); MessageBox.Show("success"); con.Close(); DataGridView1.Refresh(); }
/// <summary> /// Read data from database table and setup for /// viewing data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { DataOperations ops = new DataOperations(); bsData.DataSource = ops.GetRows(); DataGridView1.AutoGenerateColumns = false; DataGridView1.DataSource = bsData; Label1.DataBindings.Add("Text", bsData, "Identifier"); DataGridView1.ExpandColumns(); DataGridView1.CellEnter += DataGridView1_CellEnter; }
private void upDateDataGridView() { CheckForIllegalCrossThreadCalls = false; achelp = new AccessHelper(); DataTable dt = new DataTable(); string strSelectSql = "SELECT IpAddress ,DeviceNum,Dates,Times,OrderNum,CarriageNum,ArtNo,SetWeight,LoadedWeight,TotalAmount from DeviceMsg "; dt = achelp.GetDataTableFromDB(strSelectSql); DataGridView1.DataSource = dt;//SetDGVSourceFunction(ds); // ds; // DataGridView1.DataMember = "dt"; DataGridView1.Columns[DataGridView1.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); }
private void Frm_usuario_Load(object sender, EventArgs e) { // oculta elementos de la interfaz como los botones de guardar actualizar y eliminar Button1.Hide(); Button2.Hide(); Button3.Hide(); Button4.Hide(); pictureBox1.Hide(); PictureBox3.SetBounds(this.Width - 80, 25, PictureBox3.Width, PictureBox3.Height); Label6.Hide(); DataGridView1.Hide(); ComboBox1.SelectedIndex = 0; }