:confused:
I'm trying to select multiple rows in a DGV and then do something with them(delete them for example) and then apply these changes to DB. and I'm using sql server express. the problem is when i load data from a table that is bound to the DGV and then try to check the rows, only one row will be checked and as soon as i click on another row(either a checkbox or somewhere else) the other checkbox goes unchecked. i looked into the properties of the DGV and the checkbox column but couldn't figure out the problem. oh and the checkbox column is the only column in the DGV that is not bound to the table
thanks guys.

Hi, would you mind to share your code here with us? Will be easier to salve the problem.
Show us how you bind DGV to the dataTable (and stuff).

Edited 5 Years Ago by Mitja Bonca: n/a

oh before i give the code i must mention that this is a WinApp, so i dont want any Asp or anything in the code, honestly i dont know if you can use asp in winapps or not.
here is the code for filling the DGV from users table, but i don't know how this is relevant to the checkbox column on the DGV.

// refreshing the DGV on user container click event...........................................................................
        public void splitContainer1_Panel1_Click(object sender, EventArgs e)
        {

            SqlConnection main_user_con = new SqlConnection();
            main_user_con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\clubdb.mdf;Integrated Security=True;User Instance=True";
            string con_string = "select * from users";
            SqlDataAdapter userda = new SqlDataAdapter(con_string, main_user_con);
            DataTable userdt = new DataTable();
            userda.Fill(userdt);
            userdgv.AutoGenerateColumns = false;
            userdgv.DataSource = userdt;
            userdgv.Columns["id"].DataPropertyName = "id";
            userdgv.Columns["name"].DataPropertyName = "name";
            userdgv.Columns["family"].DataPropertyName = "family";
            userdgv.Columns["birthdate"].DataPropertyName = "birthdate";
            userdgv.Columns["major"].DataPropertyName = "major";
            userdgv.Columns["degree"].DataPropertyName = "degree";
            userdgv.Columns["title"].DataPropertyName = "title";
            userdgv.Columns["sex"].DataPropertyName = "sex";
            userdgv.Columns["initialdate"].DataPropertyName = "initialdate";
            userdgv.Columns["postalcode"].DataPropertyName = "postalcode";
            userdgv.Columns["address"].DataPropertyName = "address";
            userdgv.Columns["tellnum"].DataPropertyName = "tellnum";
            userdgv.Columns["cellnum"].DataPropertyName = "cellnum";
            userdgv.Columns["email"].DataPropertyName = "email";
            userdgv.Columns["workplace"].DataPropertyName = "workplace";
            userdgv.Columns["lessons"].DataPropertyName = "lessons";
        }
//...............................................................................

and i might add that i prevent the grid from auto filling from table with fields' names as column names by this line:
userdgv.AutoGenerateColumns = false;
as you can see in the code. and i might add that i want the DGV look like and email page like Gmail or yahoo that you can select some or all the rows for deleting and other stuff. and putting 2 buttons as 'select all' and 'select none' would be nice too.
thanks for your helps, i'm really kinda stuck on this

Edited 5 Years Ago by DeathEater: n/a

In my opinion, you have way too much code of DGV.
What you need is only to use DataSource property.

just and only this:

SqlConnection main_user_con = new SqlConnection();
            main_user_con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\clubdb.mdf;Integrated Security=True;User Instance=True";
            string con_string = "select * from users";
            SqlDataAdapter userda = new SqlDataAdapter(con_string, main_user_con);
            DataTable userdt = new DataTable();
            userda.Fill(userdt);
            userdgv.AutoGenerateColumns = false;
            userdgv.DataSource = new BindingSource(userdt, null); //use it this way

And then you only add a code to add a new column - checkBox column.

i dont understand at all what you mean, if by data source property you mean the data property name of the columns well i just did it in code instead of the designer, and i dont want to add the checkbox column in runtime, the column is already there, i just dont know why the user can not select more than one column in runtime. and if it can be done how do i get the selected rows to manipulate them. i gave an example, exactly like how the email pages work on web, only i want to do it in a winapp.

thank you all for reading and answering. i actually found out what the problem was that would not allow to check multiple checkboxes on a DGV in runtime by user. the DGV has a property named virtual mode, if it's set to true it won't allow multiple checks, but i really dont know what it truely does, some thing about data management says the VS itself.
thanks again

This question has already been answered. Start a new discussion instead.