Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i want to set the value of one column of gridview to true and this column type is checkedbox how can i do this"
"
 (dataGridView2.Columns[12] as DataGridViewCheckBoxColumn).value = true;
how can i do this
Posted 17-Nov-12 19:15pm
Edited 17-Nov-12 19:37pm
v2
Comments
Dominic Abraham at 18-Nov-12 1:50am
   
If the solution is helpful, mark it as answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

public DataTable Search(int m)
{
   DataTable k = new System.Data.DataTable();
   try
   {
      string str = "Data Source=C:\\Documents and Settings\\almas\\Desktop\\BazarKhodro\\khodro.sdf";
      Qconnection.ConnectionString = str;
      Qcommand.Connection = Qconnection;
      string cond="";
              
 
      string commandText = "SELECT  foroosh.date, moshtari.name, moshtari.lname,moshtari.mobile,  foroosh.type, foroosh.model, foroosh.tip, foroosh.karkard,foroosh.color, foroosh.sales, foroosh.badane,foroosh.price,foroosh.mojood,foroosh.comment  FROM foroosh INNER JOIN moshtari ON foroosh.mid = moshtari.id where foroosh.parvande=@par "+cond ;
      Qcommand.Parameters.AddWithValue("@type", dataGridView2.Rows[m].Cells[0].Value.ToString());
      Qcommand.Parameters.AddWithValue("@modelfrom", dataGridView2.Rows[m].Cells[1].Value.ToString());
      Qcommand.Parameters.AddWithValue("@modelto", dataGridView2.Rows[m].Cells[2].Value.ToString());
      Qcommand.Parameters.AddWithValue("@tip", dataGridView2.Rows[m].Cells[3].Value.ToString());
      Qcommand.Parameters.AddWithValue("@karkardfrom", dataGridView2.Rows[m].Cells[4].Value.ToString());
      Qcommand.Parameters.AddWithValue("@karkardto", dataGridView2.Rows[m].Cells[5].Value.ToString());
      Qcommand.Parameters.AddWithValue("@color", dataGridView2.Rows[m].Cells[6].Value.ToString());
      Qcommand.Parameters.AddWithValue("@pricefrom", dataGridView2.Rows[m].Cells[7].Value.ToString());
      Qcommand.Parameters.AddWithValue("@priceto", dataGridView2.Rows[m].Cells[8].Value.ToString());
      Qcommand.Parameters.AddWithValue("@par", "faal");
      Qcommand.CommandText = commandText;
      Qcommand.CommandType = CommandType.Text;
      SqlCeDataAdapter a = new SqlCeDataAdapter();
      a.SelectCommand = Qcommand;
      a.Fill(k);
      Qconnection.Open();
      Qconnection.Close();
      return k;
   }
   catch (Exception ex)
   {
      throw new Exception(ex.Message);
      return k;
   }
}
 
i want to read from data base and if value of column mojood of table is true the chech box column of gridview checked
  Permalink  
v2
Comments
Dominic Abraham at 18-Nov-12 4:21am
   
Are you expecting a single row or multiple row in this dataset 'k' "
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

As dominic has replied
 
 foreach (DataGridViewRow dgRow in dataGridView1.Rows)
            {
                var cellValue = dgRow.Cells[12] as DataGridViewCheckBoxCell;
                 //Check the Database value for true or false to make the checkbox checked or unchecked
                if(your Condition)
                cellValue.Value = true;
            }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
 
Please try the below code
 
 foreach (DataGridViewRow dgRow in dataGridView1.Rows)
            {
                var cellValue = dgRow.Cells[12] as DataGridViewCheckBoxCell;
                cellValue.Value = true;
            }
  Permalink  
Comments
f.sarikhani at 18-Nov-12 2:15am
   
this work true but i want to read data from data base and if a condition is true this checkbox is checked
Dominic Abraham at 18-Nov-12 2:27am
   
Can you post some lines of your code, so that i can correct you. What is the condition ? are you comparing the value from the database with a value of a column in gridview ?

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 422
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 250
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid