vendredi 23 avril 2021

Visual Studio C# DataGridViewColumn to DataGridViewCheckBoxColumn

mysqlCon.Open();
                MySqlDataAdapter sqlDa = new MySqlDataAdapter("ViewAllUsers", mysqlCon);
                sqlDa.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataTable dtblUsers = new DataTable();
                sqlDa.Fill(dtblUsers);
                usersGridView.DataSource = dtblUsers;
                DataGridViewColumn clmIme  = usersGridView.Columns[0];
                DataGridViewColumn clmPrezime = usersGridView.Columns[1];
                DataGridViewColumn clmOIB = usersGridView.Columns[2];
                DataGridViewColumn clmPassword = usersGridView.Columns[3];
                DataGridViewColumn clmAdmin =usersGridView.Columns[4];

This works fine. Table shows data from database. But clmAdmin is type BIT in mysql database and naturaly it shows 0 or 1 in my DataGridViewColumn. I would like to represent that value with checkBox (DataGridViewCheckBoxColumn), change that column type. I have no idea how to do it, I'm getting conversion error when I try

DataGridViewCheckBoxColumn clmAdmin = (DataGridViewCheckBoxColumn)usersGridView.Columns[4];

(DataGridViewCheckBoxColumn)usersGridView.Columns[4]' threw an exception of type System.InvalidCastException System.Windows.Forms.DataGridViewCheckBoxColumn {System.InvalidCastException}

Can someone please point me in right direction or show me how to do it? Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire