c# Datagridview de hücre alanına buton ekleme
23 Ağustos 2017 / 10:33
Burak
Merhaba arkadaşlar datagridview de bazen hücre alanın ekstra olarak buttonda eklememiz gerekebilir bunun için aşağıdaki kod satırlarını kullanabilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication13 { public partial class Form1 : Form { Button button = new Button() { Width = 25, Height = 20 }; int maxHeight = 20; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button.Visible = false; button.Parent = dataGridView1; } private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { DataGridView grid = sender as DataGridView; if (grid.CurrentCell.RowIndex == e.RowIndex && grid.CurrentCell.ColumnIndex ==e.ColumnIndex) { if (grid.CurrentCell.ColumnIndex.ToString() == "1") { button.Top = e.CellBounds.Top; button.Left = e.CellBounds.Right - button.Width; button.Height = Math.Min(e.CellBounds.Height, maxHeight); button.Text = "..."; button.Invalidate(); button.Visible = true; } } } private void dataGridView1_Enter(object sender, EventArgs e) { button.Parent = (sender as Control); } private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { } } } |
Sonuç aşağıdaki gibidir 🙂
Etiketler: c# Datagridview cell insert button
Bu Yazılarıda Okuyabilirsiniz...
çok teşekkürler, emeğine sağlık
Rica ederim, yardımcı olabildiysem ne mutlu..