我使用DataGridView
从database
(以编程方式)获取一些记录。此外,我将grid
设为只读,因此用户无法修改/编辑某些内容。与此同时,我添加了另一列(checkbox
)并且由于grid
的属性,我无法选择我想要的任何行。是否有可能只编辑一列?感谢。
代码:
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand(select, con);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = dt;
}
DataGridViewCheckBoxColumn dch = new DataGridViewCheckBoxColumn();
dch.HeaderText = "Selecteaza";
dataGridView1.Columns.Add(dch);
编辑 - 我使用此选项,我只希望我添加的列("Selecteaza"
)可编辑:
"SELECT p.cod AS Numar, p.data AS Data, c.nume AS Furnizor, d.nume AS DocFurnizor, p.doc_cod AS NrDocFurnizor, p.validat AS Validat, p.facturat AS Contat, g.nume AS Gestiune
FROM primar p INNER JOIN cf c ON p.part1=c.cf_id
INNER JOIN gestiuni g ON p.part2 = g.gest_id
INNER JOIN documente d ON p.doc_id = d.doc_id WHERE (p.tip = '2')
ORDER BY p.Data";
答案 0 :(得分:0)
为ReadOnly
设置false
到DataGridView
,然后根据需要为列分别设置ReadOnly
属性。