Hi, I am making a program in which I want to add rows in datagridview dynamically. I am also like to add combobox and textbox in cells of datagridview row.
You can add rows to the Datagrid using Columns property with Add method. Something like,
dataGridView1.Rows.Add("Windows XP");
To add combobox and Textbox to the Cells of the datagrid you can use the Sample code below,
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace BindingTexandCombo { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { //Create and fill a list to use as the custom data source var source = new AutoCompleteStringCollection(); source.AddRange(new string[] { "Chennai", "Thiruvallur", });
//Set the appropriate properties on the textbox control TextBox dgvEditBox = e.Control as TextBox; if (dgvEditBox != null) { dgvEditBox.AutoCompleteMode = AutoCompleteMode.Suggest; dgvEditBox.AutoCompleteCustomSource = source; dgvEditBox.AutoCompleteSource = AutoCompleteSource.CustomSource; } } } }
Hope this might help you.
Thanks,
Shankar
Liked By
Write Answer
How can I add rows in datafridview in c#.
Join MindStick Community
You have need login or register for voting of answers or question.
Shankar M
10-Feb-2013Hi Smith,
You can add rows to the Datagrid using Columns property with Add method. Something like,
dataGridView1.Rows.Add("Windows XP");
To add combobox and Textbox to the Cells of the datagrid you can use the Sample code below,
Hope this might help you.
Thanks,
Shankar