Whenever I click in a check box and look at the cell value changed event the value is always false if the check box was originally unchecked and always true if the checkbox was originally checked...

Update: So when I check the box - and the then the cell loses focus it changes back to its original state - but dont know why???

Why is this and how do I get around this?

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

Update:

Populating 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();
        }
有帮助吗?

解决方案

The check box editor in RadGridView is a permanent editor and the cell value will be changed only when you change the current cell. To force changing the value when the user checks the check box, you need to subscribe to the ValueChanged event of RadGridView and call the EndEdit method:

void radGridView1_ValueChanged(object sender, EventArgs e)
{
    if (radGridView1.CurrentColumn.Name == "MyCheckBoxColumnName")
    {
        radGridView1.EndEdit();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top