问题描述
如何使用DataGridViewComboBoxCell选择项目就像在ComboBox上一样
我以这种方式骑行我的DataGridView
public enum DiaSemana
{
Segunda,$ b $bTerça,
Quarta,
Quinta,
Sexta,$ b $bSábado
}
private void btnEditar_Click(object sender,EventArgs e)
{
DataGridViewCheckBoxColumn Chk = new DataGridViewCheckBoxColumn()
{
HeaderText =" Chk",
DataPropertyName =" Chk"
};
DataGridViewTextBoxColumn CodInstrumento = new DataGridViewTextBoxColumn()
{
HeaderText =" Cod",
Name =" CodInstrumento"
};
DataGridViewTextBoxColumn Instrumento = new DataGridViewTextBoxColumn()
{
HeaderText =" Instrumento",
Name =" instrumento"
};
DataGridViewComboBoxColumn DiaAula = new DataGridViewComboBoxColumn()
{
HeaderText =" Dia da Aula",
Name =" DiaAula"
};
DiaAula.DataSource = Enum.GetNames(typeof(DiaSemana));
DiaAula.ValueType = typeof(int);
DataGridViewTextBoxColumn DeHoras = new DataGridViewTextBoxColumn()
{
HeaderText =" De",
DataPropertyName =" DeHoras"
};
DataGridViewTextBoxColumn AteHoras = new DataGridViewTextBoxColumn()
{
HeaderText ="Até",
DataPropertyName =" DeHoras"
};
dtInstrumentosEstudo.Columns.AddRange(Chk,CodInstrumento,Instrumento,DiaAula,DeHoras,AteHoras);
}
以这种方式填充我的DataGridView
private void btnTeste_Click(object sender,EventArgs e)
{dtInstrumentosEstudo.Rows.Add(true," A"," B",null," C"," ; D");
}
问题是设置DataGridViewComboBoxCell的值,因为使用selectedindex函数可以使用ComboBox
How to select an item using DataGridViewComboBoxCell just like on ComboBox
I rode my DataGridView this way
public enum DiaSemana { Segunda, Terça, Quarta, Quinta, Sexta, Sábado } private void btnEditar_Click(object sender, EventArgs e) { DataGridViewCheckBoxColumn Chk = new DataGridViewCheckBoxColumn() { HeaderText = "Chk", DataPropertyName = "Chk" }; DataGridViewTextBoxColumn CodInstrumento = new DataGridViewTextBoxColumn() { HeaderText = "Cod", Name = "CodInstrumento" }; DataGridViewTextBoxColumn Instrumento = new DataGridViewTextBoxColumn() { HeaderText = "Instrumento", Name = "instrumento" }; DataGridViewComboBoxColumn DiaAula = new DataGridViewComboBoxColumn() { HeaderText = "Dia da Aula", Name = "DiaAula" }; DiaAula.DataSource = Enum.GetNames(typeof(DiaSemana)); DiaAula.ValueType = typeof(int); DataGridViewTextBoxColumn DeHoras = new DataGridViewTextBoxColumn() { HeaderText = "De", DataPropertyName = "DeHoras" }; DataGridViewTextBoxColumn AteHoras = new DataGridViewTextBoxColumn() { HeaderText = "Até", DataPropertyName = "DeHoras" }; dtInstrumentosEstudo.Columns.AddRange(Chk, CodInstrumento, Instrumento, DiaAula, DeHoras, AteHoras); }
and populate my DataGridView this way
private void btnTeste_Click(object sender, EventArgs e) {
dtInstrumentosEstudo.Rows.Add(true, "A", "B", null, "C", "D");
}
The problem is setting the value of DataGridViewComboBoxCell as it's possible with ComboBox using the selectedindex function
这篇关于如何使用DataGridViewComboBoxCell选择一个项目,就像在ComboBox上一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!