i have been strugeling with this for some time now and its driving me crazy. This is the situation:
I have a bounded DataGridView
i designed this with the visual studio designer. All the information shows accordingly.
in my DataGridView
i have 2 ComboBoxes
in here the data is also correctly displayed. I want that if i click on the ComboBoxe
a list of options shows.
Because the DataGridView
is bounded to a source i can not use the ComboBox.Items.Add()
method. So i created another Datasource in the designer and in runtime i change the datasource
for that specific combobox. Now the list shows shows the options that i want, yeey !
Now, i want to save this newly added or changed row to the database.. so i use the following method for this (i call the method on the RowLeave
event from the DataGridView
):
if (tasksDataSet.HasChanges()
{
try
{
tasksBindingSource.EndEdit();
tasksDataSet.GetChanges();
tasksTableAdapter.Update(tasksDataSet);
}
catch (Exception ex)
{
}
}
This won't work for the ComboBoxes
since this is another datasource.
So basicly what i want is:
DataGridView
DataGridViewComboBox
DataGridView
to the database How can i make this work ?
if your problem is to save current data which is given to Grid view. than i suggest try to use session . while binding data to DataSource assign it to session["SomeID"] . if your changing binding then again assign same session to it.
next step convert session to what ever you want to save.
ex:
//Datasource.
list<User> DataBoundSource = new list<User>();
DataGrid.DataSource = DataBoundSource;
DataGrid.DatBind();
//Assign to Session where you are binding this
//every time
Session["SameID"] = lsDataBoundSOurce;
//your code.
...
...
...
//covert that session to Datasource you want to save.
list<User> saveData = (list<User>) Session["SameID"];
this is the basic idea i got. i hop this will help you. please give it +1 if it help you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.