This is a migrated thread and some comments may be shown as answers.

Threestate Checkboxcolumn crashes when scrolling

2 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jasper
Top achievements
Rank 1
Jasper asked on 19 Jan 2016, 12:55 PM

Hello there,

I have some problems with the gridview control when using three-stated checkboxcolumns. To recreate the problem, create a new telerik winforms project and in the mainform add a gridview. Dock this gridview to the form. 

 Then, add the following columns and change the options as follows:

GridViewTextBoxColumm

 FieldName: Id

 Name: Id

 MinWidth: 80 (important for later)

 

GridViewTextBoxColumm
FieldName: Name
Name: Name
MinWidth: 150

 

GridViewCheckBoxColumn

FieldName: Test1

Name: Test1

MinWidth: 80

ThreeState: true

 

GridViewCheckBoxColumn
FieldName: Test2
Name: Test2
MinWidth: 80
ThreeState: true

 

GridViewCheckBoxColumn
FieldName: Test3
Name: Test3
MinWidth: 80
ThreeState: true

 

GridViewDateTimeColumn

FieldName: CurrentDateTime

Name: CurrentDateTime

MinWidth: 200

 

GridViewDecimalColumn

FieldName: Nr

Name: Nr

 

GridViewCheckBoxColumn

FieldName: Test4

Name: Test4

MinWidth: 80

 

The extra columns and minimal width are only there to make the sure you can scroll horizontally.

Change the codebehind for RadForm1 to the following:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
 {
     public RadForm1()
     {
         InitializeComponent();
     }
 
     private void RadForm1_Load(object sender, EventArgs e)
     {
         this.radGridView1.DataSource = GetTestData();
     }
 
     private List<TestData> GetTestData()
     {
         List<TestData> test = new List<TestData>();
 
         for (int i = 0; i < 100; i++)
         {
             test.Add(new TestData()
                 {
                     Id = i + 1,
                     Name = i.ToString(),
                     Test1 = i % 2 == 0 ? true : (bool?)null,
                     Test2 = i % 3 == 0 ? false : (bool?)null,
                     Test3 = i % 5 == 0 ? (bool?)null : false,
                     CurrentDateTime = DateTime.Now,
                     Nr = i,
                     Test4 = i % 2 == 0 ? true : false
                 });
         }
 
         return test;
     }
 }

To trigger the error, run the project, do not enlarge the window, and try to add a new line. Fill in a new id and a new name, keep Test1 to it's initial (third) state and uncheck Test2. Then, without pressing enter, scroll left and right by grabbing the horizontal scrollbar and moving quickly left and right. At that moment you should get the following error:

 

TargetInvocationException:  
bij System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   bij System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   bij System.Reflection.RuntimeMethodInfo.UnsafeInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   bij System.Delegate.DynamicInvokeImpl(Object[] args)
   bij System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
   bij System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
   bij System.Threading.ExecutionContext.RunInternal(ExecutionContext
(Innerexception)
NullReferenceException: 
bij Telerik.WinControls.UI.BaseGridEditor.OnValueChanging(ValueChangingEventArgs e)
   bij Telerik.WinControls.UI.RadCheckBoxEditor.SetValue(Object value)
   bij Telerik.WinControls.UI.RadCheckBoxEditor.set_ThreeState(Boolean value)
   bij Telerik.WinControls.UI.GridCheckBoxCellElement.SetThreeState(GridViewColumn column)
   bij Telerik.WinControls.UI.GridCheckBoxCellElement.Initialize(GridViewColumn column, GridRowElement row)
   bij Telerik.WinControls.UI.GridVirtualizedCellElement.Attach(GridViewColumn data, Object context)
   bij Telerik.WinControls.UI.GridCheckBoxCellElement.Attach(GridViewColumn data, Object context)

 

So, my question would be: what am I doing wrong and how can I avoid this?

 

Thanks in advance

 Then, add the following columns and cha
 Then, add the following columns and cha

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Jan 2016, 01:47 PM
Hello Jasper,

Thank you for writing.

The provided detailed explanation is greatly appreciated. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use a custom cell:

public class MyGridCheckBoxCellElement : GridCheckBoxCellElement
{
    public MyGridCheckBoxCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
    {
    }
 
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(GridCheckBoxCellElement);
        }
    }
 
    public override bool IsCompatible(GridViewColumn data, object context)
    {
        GridViewCheckBoxColumn col = data as GridViewCheckBoxColumn;
        if (col != null)
        {
            return col.ThreeState == ((RadCheckBoxEditor)this.Editor).ThreeState;
        }
        return base.IsCompatible(data, context);
    }
}
 
private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.CellType == typeof(GridCheckBoxCellElement))
    {
        e.CellElement = new MyGridCheckBoxCellElement(e.Column, e.Row);
    }
}

 

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jasper
Top achievements
Rank 1
answered on 20 Jan 2016, 02:33 PM

Hello Dess,

Thank you for the quick reply and the work-around. I will check whether or not this work-around is sufficient for our project and will get back to you if not. 

Tags
GridView
Asked by
Jasper
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Jasper
Top achievements
Rank 1
Share this question
or