C#中的chechbox列 [英] chechbox column in c#

查看:61
本文介绍了C#中的chechbox列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将gridview的一列的值设置为true,并且选中此列类型,我该怎么做呢?"
"

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

推荐答案



请尝试以下代码

Hi

Please try the below code

foreach (DataGridViewRow dgRow in dataGridView1.Rows)
           {
               var cellValue = dgRow.Cells[12] as DataGridViewCheckBoxCell;
               cellValue.Value = true;
           }


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;
   }
}



我想从数据库中读取数据,并且如果表的列mojood的值为true,则选中gridview的复选框框



i want to read from data base and if value of column mojood of table is true the chech box column of gridview checked


多米尼克回答了

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;
           }


这篇关于C#中的chechbox列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆