1

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 ComboBoxea 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:

  • Use a datasource for the DataGridView
  • Change/Add items to the DataGridViewComboBox
  • Save the changed made to the (complete) DataGridView to the database

How can i make this work ?

Chancho
  • 1,930
  • 2
  • 15
  • 20

1 Answers1

1

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

Avinash patil
  • 1,689
  • 4
  • 17
  • 39
  • This will change the Datasource for the entire datagrid, the problem with saving is saving is that i have another Datasource for the combobox – Chancho Oct 30 '13 at 18:45
  • i am not telling you to change the datasource. assign your datasource to session and then save that session by converting it. if possible please post some code so i can help you. Thanks for reply. – Avinash patil Oct 30 '13 at 18:49