RadGridView复选框控件始终为false

时间:2013-06-28 19:11:32

标签: c# winforms telerik telerik-grid radgridview

每当我单击复选框并查看单元格值更改事件时,如果最初取消选中该复选框,则该值始终为false;如果最初选中该复选框,则该值始终为true ...

更新: 因此,当我检查框时 - 然后细胞失去焦点,它会变回原来的状态 - 但不知道为什么???

为什么会这样,我该如何解决这个问题?

private void CellValueChanged(object sender, GridViewCellEventArgs e)
        {
//e.Value always false or true depending on original state
}

更新

填充GridView

public void PopulateEvents(User user)
        {
            if (user.EventSubscriptions.Count < 1)
                AddDefaultEvents(user);

            var query = user.EventSubscriptions.Join(sp.Events, r => r.EventId, p => p.EventId, (r, p) =>
                new { r.UserId, r.EventSubscriptionId, p.EventType, p.EventAction, r.IsAlert, r.IsEmail, r.AlertLevel })
                .Where(pr => pr.UserId == user.ID);

            BindingSource temp = new BindingSource() { DataSource = query };
            RGVAlerts.DataSource = temp; 

            //RGVAlerts.DataSource = query;

            foreach (var column in RGVAlerts.Columns)
            {
                switch (column.HeaderText)
                {
                    case "EventType":
                        column.HeaderText = "Category"; break;
                    case "EventAction":
                        column.HeaderText = "Event Action"; break;
                    case "IsAlert":
                        column.HeaderText = "Send Alert";
                        column.ReadOnly = false;
                        break;
                    case "IsEmail":
                        column.HeaderText = "Send Email";
                        column.ReadOnly = false; break;

                    case "AlertLevel":
                        column.HeaderText = "Alert Level"; break;
                }
            }
            RGVAlerts.Columns.Remove("UserId");
            RGVAlerts.Columns.Remove("AlertLevel");
            RGVAlerts.Columns.Remove("EventSubscriptionId");

            GridViewComboBoxColumn comboLevel = new GridViewComboBoxColumn();
            comboLevel.DataSource = new string[] { "INFORMATION", "MILD", "SEVERE", "COUNT" };

            RGVAlerts.Columns.Add(comboLevel);
            comboLevel.FieldName = "AlertLevel";
            comboLevel.HeaderText = "AlertLevel";

            RGVAlerts.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
            foreach (GridViewDataColumn column in RGVAlerts.Columns)
            {
                column.BestFit();
                column.Width += 58;

            };
            RGVAlerts.AllowCellContextMenu = true;
            RGVAlerts.AllowEditRow = true;
            RGVAlerts.CausesValidation = true;

            RGVAlerts.Refresh();
        }

1 个答案:

答案 0 :(得分:1)

RadGridView中的复选框编辑器是一个永久编辑器,只有在更改当前单元格时才会更改单元格值。要在用户选中复选框时强制更改值,您需要订阅RadGridView的ValueChanged事件并调用EndEdit方法:

void radGridView1_ValueChanged(object sender, EventArgs e)
{
    if (radGridView1.CurrentColumn.Name == "MyCheckBoxColumnName")
    {
        radGridView1.EndEdit();
    }
}