DataGridView行禁用取决于1个单元格的值
问题描述:
嗨
我有一个用未绑定数据填充的DataGridView,并且我没有使用DataView,但我希望根据该行中的单元格值禁用对该行的编辑.
我是Windows Form编程的新手,我发现很难找到关于该主题的任何信息.
谁能帮忙
这是设置datagridview的代码(如果有帮助的话)
Hi
I have a DataGridView that is populated with unbound data and im not using a DataView, I wish to disable editing on a row depending on a cell value in that row.
I am new to Windows Form Programming an im finding it hard to find any informaton on the subject.
Can anyone help
Here is the code (if it helps) that sets up the datagridview
private void button1_Click(object sender, EventArgs e)
{
String CountrySelect = Country.SelectedValue.ToString();
SQLProcess defaults = new SQLProcess();
DataSet info = defaults.DefaultCountryConfig(CountrySelect);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.RowHeadersVisible = false;
SetupColumns(info);
dataGridView1.DataSource = info.Tables["Country"];
Country.Enabled = false;
button1.Enabled = false;
}
private void SetupColumns(DataSet info)
{
//Setup variables for gridview
//Setup
DataGridViewTextBoxColumn FName = new DataGridViewTextBoxColumn();
FName.DataPropertyName = "FName";
FName.HeaderText = "Field Name";
FName.ValueType = typeof(String);
FName.Frozen = true;
dataGridView1.Columns.Add(FName);
SQLProcess Fieldtype = new SQLProcess();
DataSet DTypes = Fieldtype.FieldTypes();
DataGridViewComboBoxColumn FType = new DataGridViewComboBoxColumn();
FType.DataPropertyName = "Ftype";
FType.HeaderText = "Field Type";
FType.DataSource = DTypes.Tables["FieldTypes"];
FType.DisplayMember = "FieldType";
FType.ValueMember = "FieldTypeValue";
FType.Frozen = true;
FType.Width = 100;
dataGridView1.Columns.Add(FType);
DataGridViewTextBoxColumn Position = new DataGridViewTextBoxColumn();
Position.DataPropertyName = "FPosition";
Position.HeaderText = "Position";
Position.ValueType = typeof(Int32);
Position.Frozen = true;
dataGridView1.Columns.Add(Position);
DataGridViewCheckBoxColumn Requierd = new DataGridViewCheckBoxColumn();
Requierd.HeaderText = "Requierd";
Requierd.Frozen = true;
Requierd.Width = 50;
dataGridView1.Columns.Add(Requierd);
DataGridViewCheckBoxColumn Option = new DataGridViewCheckBoxColumn();
Option.HeaderText = "Option";
Option.DataPropertyName = "Foption";
Option.ValueType = typeof(String);
Option.Frozen = true;
Requierd.Width = 30;
dataGridView1.Columns.Add(Option);
}
在此先感谢.
[edit]将内联代码转换为代码块-OriginalGriff [/edit]
thanks in advance.
[edit]Inline code converted to code block - OriginalGriff[/edit]
答
尝试一下
try this one
if(dataGridView1.CurrentRow.Cells["the name of the column you wish to check its value"].Value=="whatever the value to check")
{
dataGridView1.currentRow.ReadOnly=true;
}
希望我能帮忙
:-)
I hope I helped
:-)
您好xenosnoop,
Hi xenosnoop,
dataGridView1["(your desired column)", dataGridView1.CurrentRow.Index].ReadOnly = dataGridView1["(the column to take the check value)", dataGridView1.CurrentRow.Index].Value;
希望对您有所帮助,
:)
I hope this help,
:)