public static void EditGrid(DataGridView Grid) { Boolean vGrid = Grid.Visible; Grid.Visible = true; Grid.Columns[1].Width = 100; Grid.AllowUserToResizeRows = false; Grid.AllowUserToAddRows = false; Grid.ReadOnly = true; for (int i = 0; i < Grid.Rows.Count; i++) { Grid.AutoResizeRow(i); } Grid.Visible = vGrid; }
//_________________________________________________________________________________________________________ //_________________________________________________________________________________________________________ public static void CopyRow(DataGridView dgo, DataGridView dgd, int Row, bool bSort, bool bMultiValue) { bool bHayImgs = false; dgd.Rows.Clear(); dgd.Columns.Clear(); dgd.Columns.Add("R", "R"); dgd.Columns.Add(dgo[0, Row].Value.ToString(), dgo[0, Row].Value.ToString()); DataGridViewImageColumn imgCol = new DataGridViewImageColumn(); dgd.Columns.Add(imgCol); dgd.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgd.Columns[0].Width = 30; for (int i = 2; i < dgo.Columns.Count; i++) { dgd.Rows.Add(); dgd[0, dgd.Rows.Count - 1].Value = " "; dgd[1, dgd.Rows.Count - 1].Value = dgo.Columns[i].Name; dgd[1, dgd.Rows.Count - 1].Style.ForeColor = Color.Blue; dgd[1, dgd.Rows.Count - 1].Style.Font = new Font(dgd.Font, FontStyle.Bold); dgd[2, dgd.Rows.Count - 1].Value = Config.DefImage; // If it is not multiline it is shown as is if (!bMultiValue) { dgd.Rows.Add(); dgd[0, dgd.Rows.Count - 1].Value = ""; dgd[1, dgd.Rows.Count - 1].Value = (dgo[i, Row].Value == null ? "" : dgo[i, Row].Value).ToString(); if (Config.ExistImage(dgo.Columns[i].Name, dgo[0, Row].Value.ToString(), 0)) { Bitmap img = Config.GetImage(dgo.Columns[i].Name, dgo[0, Row].Value.ToString(), 0); dgd[2, dgd.Rows.Count - 1].Value = img; dgd.AutoResizeRow(dgd.Rows.Count - 1, DataGridViewAutoSizeRowMode.AllCells); dgd.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; bHayImgs = true; } else { dgd[2, dgd.Rows.Count - 1].Value = Config.DefImage; } continue; } // If it is multivalue it is splitted by Config.SeparatorC List <string> tmp = (dgo[i, Row].Value == null ? "" : dgo[i, Row].Value).ToString().Split(Config.SeparatorC).ToList(); if (bSort) { tmp.Sort(); } for (int j = 0; j < tmp.Count; j++) { dgd.Rows.Add(); dgd[0, dgd.Rows.Count - 1].Value = ""; dgd[1, dgd.Rows.Count - 1].Value = tmp[j]; if (Config.ExistImage(dgo.Columns[i].Name, dgo[0, Row].Value.ToString(), j)) { Bitmap img = Config.GetImage(dgo.Columns[i].Name, dgo[0, Row].Value.ToString(), j); dgd[2, dgd.Rows.Count - 1].Value = img; dgd.AutoResizeRow(dgd.Rows.Count - 1, DataGridViewAutoSizeRowMode.AllCells); dgd.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; bHayImgs = true; } else { dgd[2, dgd.Rows.Count - 1].Value = Config.DefImage; } } } for (int i = 0; i < dgd.Rows.Count; i++) { if (dgd[0, i].Value.ToString() == " ") { continue; } string s = dgd[1, i].Value.ToString(); if (s == "") { continue; } int cont = 0; for (int j = 0; j < dgd.Rows.Count; j++) { if (dgd[0, j].Value.ToString() != " " && dgd[1, j].Value.ToString() == s) { cont++; } } dgd[0, i].Value = "" + cont; } // If there does not exists a image column, the last column is removed if (!bHayImgs) { dgd.Columns.RemoveAt(2); } }
//</snippet3> //<snippet4> private void SizeThirdRow(Object sender, EventArgs e) { dataGridView1.AutoResizeRow( 2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader); }