Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have thiw grid view in which i load from the database 3 columns. Looks like this
C#
ID|  Server| Status
 1|  Tm2323|  checked
 2|  Tm2356|  unchecked
 3|  Xg2355|  checked
 4|  Hgd345|  checked


So i want to do this uncheck or check a server in the third column of the gridview, and after thath when i click a submit button that i have in my app the, database to get updated and the gridview to refresh showing the new results.
Can anyone guide me? because i've tried everything i could but i just can't make this work. I'm out of ideas.
Posted
Updated 25-Sep-13 4:09am
v2
Comments
Thanks7872 25-Sep-13 10:11am    
What is checked/unchecked? Is it checkbox? If so,do you want to perform some action based on the status of the checkbox?
Ioan-Alexandru 25-Sep-13 10:34am    
yes, it's a checkbox column in the gridview which i upload from the database , in the access database is't a ye/no datatype. but i've managed to solve my problem. i had only to modify a propriety when i uploaded the data in the gridview...

dataGridViewServers.ReadOnly = true; i had to change to dataGridViewServers.ReadOnly =false;
Ioan-Alexandru 25-Sep-13 10:35am    
now i can modify the cheboxes and from now on it's easy the rest of the updates i have to make:)
Thanks7872 25-Sep-13 10:51am    
Well done.It will be good if you add the solution below and show how you solved it.That would be beneficial for others also.

use the save method when the (cell end edit) has been fired
 
Share this answer
 
C#
string SQLString;

SQLString = @"SELECT        tblServers.ID, tblServers.ServerName, tblServers.Status
              FROM            (tblServers)";

OleDbCommand SQLQuery = new OleDbCommand();
DataTable data = null;
dataGridViewJidoka.DataSource = null;
SQLQuery.Connection = null;
OleDbDataAdapter dataAdapter = null;
dataGridViewJidoka.Columns.Clear(); // <-- clear columns
//---------------------------------
SQLQuery.CommandText = SQLString;
SQLQuery.Connection = database;
data = new DataTable();
dataAdapter = new OleDbDataAdapter(SQLQuery);
dataAdapter.Fill(data);
dataGridViewServers.DataSource = data;
dataGridViewServers.AllowUserToAddRows = false; // remove the null line
dataGridViewServers.ReadOnly = true;
dataGridViewServers.Columns[0].Visible = false;
dataGridViewServers.Columns[1].Width = 140;
dataGridViewServers.Columns[2].Width = 53;


In order to be able to check/uncheck a checkbox column imported from the data base into a datagridview, youu have to modify the underlined line of code like this:

C#
dataGridViewServers.ReadOnly = false;
. now it will work just fine.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900