TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mukesh shah
NA
14
717
add dynamically datagridviewcombobox in datagridview
Oct 15 2016 11:14 PM
i want to add dynamically combobox in datagridview on particular gride cell in window form
from two diff datatable now in getting problem " Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
code : window form application
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlDataAdapter ad = new SqlDataAdapter("select * from test;select * from dis", con);
con.Open();
DataSet ds = new DataSet();
ad.Fill(ds);
DataTable dt = ds.Tables[0];
DataTable dt1 = ds.Tables[1];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
for (int j = 0; j <= dt.Columns.Count - 1; j++)
{
//string conl = Convert.ToString(dt.Columns[j]);
// dataGridView1.Columns.Add(conl, conl);
DataGridViewComboBoxColumn com = new DataGridViewComboBoxColumn();
// ComboBox com = new ComboBox();
com.DataSource = dt1;
com.ValueMember = "Id";
com.DisplayMember = "displayname";
DataRow dr = dt.NewRow();
// com.SelectedValue = dt.Rows[i][j].ToString();
string p = dt1.Rows[i][j].ToString();
//dataGridView1.Columns[j].Width = 80;
dataGridView1.DataSource = dt;
if (p == "101")
{
string list = p.CompareTo("101").ToString();
string list1 = p.CompareTo("102").ToString();
com.DataSource = null;
com.Items.Clear();
com.Items.Add(list);
}
dataGridView1.Rows.Add(dr);
}
}
}
}
Reply
Answers (
1
)
Alerting message using textboxes than only codes
Deployment error with Xamarin android application