public static void SettOppDGW(DataGridView dgw, bool kunles=true, bool ErClickAble = true,bool FilterFelt = false) { dgw.ReadOnly = kunles; dgw.AllowUserToAddRows = !kunles; dgw.AllowUserToDeleteRows=!kunles; dgw.ClearSelection(); dgw.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgw.MultiSelect = false; dgw.RowHeadersVisible = !kunles; dgw.AlternatingRowsDefaultCellStyle.BackColor = Color.LightCyan; dgw.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; dgw.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells; if (kunles) { dgw.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgw.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal; } if (ErClickAble) { dgw.MouseMove += new MouseEventHandler(dgwMouseOver); dgw.MouseLeave +=new EventHandler(dgwMouseExit); } if (dgw.Name == "dgwForbedringstabell") { dgw.CellFormatting += new DataGridViewCellFormattingEventHandler(dgwMinSideForbedringCellFormatting); dgw.DefaultCellStyle.WrapMode = DataGridViewTriState.True; } if (FilterFelt) { int TextBoxHeight = 25; int VenstreAkk = 0; dgw.Height = dgw.Height - TextBoxHeight; dgw.Location = new Point(dgw.Location.X, dgw.Location.Y + TextBoxHeight); Form f = dgw.Parent.FindForm(); foreach (DataGridViewColumn c in dgw.Columns) { if (c.Visible) { TextBox a = new TextBox(); a.Name = "AutoFilterTextBox " + c.DataPropertyName.ToString(); a.Height = TextBoxHeight-1; a.Location = new Point(dgw.Location.X + VenstreAkk, dgw.Location.Y - TextBoxHeight+2); a.Width=c.Width; a.BackColor = Color.Yellow; a.Validated+=new EventHandler(Filtrer); VenstreAkk = a.Location.X + a.Width; f.Controls.Add(a); } } } }
private static void Filtrer(object sender, EventArgs e) { TextBox tb = (TextBox)sender; Form f = tb.Parent.FindForm(); string FilterString = ""; string verdi = ""; foreach (Control c in f.Controls) { foreach (Control d in c.Controls) { string a = d.Name; } if (c.Name.Length > 17) { if (c.Name.Substring(0, 17) == "AutoFilterTextBox") { if (c.Text != "") { verdi = c.Text; if (!Snacks.IsInteger(verdi)) { verdi = "'" + c.Text + "'"; } FilterString = FilterString + c.Name.Substring(17) + "=" + verdi + ";"; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)