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. Thanks.
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
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Hi 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