Last active
February 2, 2019 02:47
-
-
Save anytizer/65ffb17385a81c95ca38996e7ae47d81 to your computer and use it in GitHub Desktop.
Data Grid View default controls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataGridView1.AllowDrop = false; | |
dataGridView1.AllowUserToAddRows = false; | |
dataGridView1.AllowUserToDeleteRows = false; | |
dataGridView1.AllowUserToOrderColumns = false; | |
dataGridView1.AllowUserToResizeColumns = false; | |
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige; | |
dataGridView1.AutoGenerateColumns = true; // change this | |
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; | |
dataGridView1.BackgroundColor = Color.Honeydew; | |
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Yellow; | |
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9F, FontStyle.Bold); | |
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.Green; | |
dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; | |
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; | |
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Salmon; | |
dataGridView1.EnableHeadersVisualStyles = false; | |
dataGridView1.MultiSelect = false; | |
dataGridView1.ReadOnly = true; | |
dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; | |
dataGridView1.RowHeadersDefaultCellStyle.Padding = new Padding(dataGridView1.RowHeadersWidth); | |
dataGridView1.RowHeadersVisible = false; | |
dataGridView1.RowTemplate.Height = 16; | |
dataGridView1.RowTemplate.Resizable = DataGridViewTriState.False; | |
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Form1() | |
{ | |
InitializeComponent(); | |
dataGridView1.CellContentClick += new DataGridViewCellEventHandler(dataGridView1_CellContentClick); | |
dataGridView1.CellContentDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellContentDoubleClick); | |
dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick); | |
dataGridView1.CellValidated += new DataGridViewCellEventHandler(dataGridView1_CellValidated); | |
dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating); | |
dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged); | |
dataGridView1.DragDrop += new DragEventHandler(dataGridView1_DragDrop); | |
dataGridView1.DragEnter += new DragEventHandler(dataGridView1_DragEnter); | |
dataGridView1.MouseDown += new MouseEventHandler(dataGridView1_MouseDown); | |
dataGridView1.MouseMove += new MouseEventHandler(dataGridView1_MouseMove); | |
dataGridView1.RowsRemoved += new DataGridViewRowsRemovedEventHandler(dataGridView1_RowsRemoved); | |
dataGridView1.SelectionChanged += new EventHandler(dataGridView1_SelectionChanged); | |
dataGridView1.UserAddedRow += new DataGridViewRowEventHandler(dataGridView1_UserAddedRow); | |
dataGridView1.UserDeletingRow += new DataGridViewRowCancelEventHandler(dataGridView1_UserDeletingRow); | |
dataGridView1.UserDeletingRow += new DataGridViewRowCancelEventHandler(dataGridView1_UserDeletingRow); | |
} | |
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_SelectionChanged(object sender, EventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_MouseMove(object sender, MouseEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_MouseDown(object sender, MouseEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_DragEnter(object sender, DragEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_DragDrop(object sender, DragEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) | |
{ | |
//throw new NotImplementedException(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// makes columns not sortable | |
for (int col = 0; col < dataGridView1.Columns.Count; ++col) | |
{ | |
dataGridView1.Columns[col].Resizable = DataGridViewTriState.False; | |
dataGridView1.Columns[col].SortMode = DataGridViewColumnSortMode.NotSortable; | |
dataGridView1.Columns[col].ReadOnly = true; | |
} | |
// readonly cells - controlled individually | |
for (int r = 0; r < dataGridView1.Rows.Count; ++r) | |
{ | |
for(int c=0; c< dataGridView1.Rows[r].Cells.Count; ++c) | |
{ | |
dataGridView1.Rows[r].Cells[c].ReadOnly = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data source example | |
orderingEntities oe = new orderingEntities(); | |
dataGridView1.DataSource = (from t in oe.customers select new { t.first_name, t.last_name, t.phone_number, t.customer_email }).ToList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handling confirmation dialog | |
DialogResult d = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); | |
if (d == DialogResult.Yes) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
View for more details