0

Im trying to delete 2 checkbox columns from datagridview because Im trying to update data, so basically I need a way to delete those columns (Im dropping all columns besides those 2 and putting a new datatable with updated data from database) or to Update columns when a button "save" is pressed.

To better explane the problem, here are some screenshots:

Before pressing "save":

enter image description here

After pressing "save": enter image description here

My idea of updating datagridview:

        NpgsqlDataAdapter da = new NpgsqlDataAdapter(command_odjel_id);
        dt = new DataTable();
        da.Fill(dt);
        Radni_sati_tablica.DataSource = dt;

After that I add those 2 checkbox columns ( there is a query for filling those checkboxes but thats irelevant for this question):

        DataGridViewCheckBoxColumn bolovanje = new DataGridViewCheckBoxColumn();
        bolovanje.HeaderText = "Bolovanje";
        bolovanje.Width = 30;
        Radni_sati_tablica.Columns.Insert(0, bolovanje);

        DataGridViewCheckBoxColumn godisnji = new  DataGridViewCheckBoxColumn(); 
        godisnji.HeaderText = "Godisnji";
        godisnji.Width = 30;
        Radni_sati_tablica.Columns.Insert(1, godisnji);

After that I do Update with the query and I finish with:

                Radni_sati_tablica.DataSource=null;
                Radni_sati_tablica.DataSource = dt;
                Radni_sati_tablica.Update();

Basically all I need is to update table with new data that has been inputed, I just need a way to do it.

4
  • 2
    Show the updating code? Check that DatagridView.AutoGenerateColumns = false. But without the code - how you load data, update data it is difficult to answer Commented Mar 9, 2017 at 12:17
  • Share some of your code, for example updating code Commented Mar 9, 2017 at 12:18
  • @Fabio there you go =) Commented Mar 9, 2017 at 13:37
  • 1
    Do not add new columns to the DataGridView - instead create and add columns to the DataTable - then when you set new DataTable to the DataGridView.DataSource manually added columns will be gone. Commented Mar 9, 2017 at 14:57

1 Answer 1

1

Good day! In order to delete and update in SQL, you must use the commands: UPDATE and DELETE.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.