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