How to display a selected item from a combobox into a gridvi
what i want to do is basically is once an item is selected in the combobox ,it should directly be added into the datagridview once i click on a button called add in a simple windows form application. please help
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 12:23 AM EDT
dt.Columns.Add("Name");
dataGridView1.DataSource = dt;
under Add Button Write this Code
dt.Rows.Add(comboBox1.SelectedItem.ToString());
If this helps u plz Mark as Answer
shosho shosho56 reputationPosted May 3, 2015, 12:44 AM EDT
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dataGridView1.DataSource = dt;
shosho shosho56 reputationPosted May 3, 2015, 1:06 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 1:10 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 1:12 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 2:42 AM EDT
This is how i am doing it..
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 3:14 AM EDT
make DAtatable global ,, declare outside of block
shosho shosho56 reputationPosted May 3, 2015, 3:43 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 3:49 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 4:07 AM EDT
WinCore.Domain.Course
WinCore.Domain.GPA
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 4:10 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 4:12 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 4:14 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 4:17 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 4:20 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 4:22 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 4:25 AM EDT
shosho shosho56 reputationPosted May 3, 2015, 4:27 AM EDT
Isham KhanRank #2,573 · 543 reputationPosted May 3, 2015, 4:39 AM EDT
Susovan Biswas17 reputationPosted May 14, 2015, 2:14 AM EDT
First globally declare your datatable:-
public static DataTable dt = new DataTable();
put the following code inside the form load event:
Put the following code inside the button click event.
dr = dt.NewRow();
dt.Rows.Add(dr);
dt.AcceptChanges();
dataGridView1.DataSource = dt;
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts