0

I have a binding list which I use as a datasource for my datagridview. I use iNotify to update my list whenever the cell value has changed. Which then writes to an Access Database. However I need a way to validate the input and make it easy for users to know what type of data is expected.

IE My "Shift" Column needs 3 shift options. I suspect I can do this with a combobox, but I'm not quite sure how to change the celltype, and still have it update my Binding List on update, by just binding my list as the datagridview's datasource.

Any hints would be awesome.

4

1 回答 1

1

你在寻找这样的东西吗?

    private void Form1_Load(object sender, EventArgs e)
    {
        BindingList<Shift> bindingList = new BindingList<Shift>();           
        bindingList.Add(new Shift(ShiftType.SHIFT1));
        bindingList.Add(new Shift(ShiftType.SHIFT2));
        bindingList.Add(new Shift(ShiftType.SHIFT3));
        bindingList.Add(new Shift(ShiftType.SHIFT1));

        var ShiftColumn = new DataGridViewComboBoxColumn();
        dataGridView1.Columns.Add(ShiftColumn);

        dataGridView1.AutoGenerateColumns = false;
        dataGridView1.DataSource = bindingList;
        ShiftColumn.DataPropertyName="shiftType";
        ShiftColumn.DataSource = new List<ShiftType> { ShiftType.SHIFT1, ShiftType.SHIFT2, ShiftType.SHIFT3 };


    }

}
class Shift
{

    public ShiftType shiftType { get; set; }


    public Shift(ShiftType shiftType)
    {
        this.shiftType = shiftType;

    }

}
enum ShiftType
{
    SHIFT1 ,
    SHIFT2,
    SHIFT3 
}
于 2013-11-09T18:04:25.943 回答