I have a GridView with a GridViewComboBoxColumn for choosing units of measure. My grid is bound to a DataTable of parts data. One of the fields for a part is 'unit of measure' but it is not a required field. I am using the Excel-like filtering. If I have a null value in the 'unit of measure' field and I click the filter icon, I get an exception that says: "Object reference not set to an instance of an object.". This only happens when I have a null value for that field in one or more rows. Here is part of the stack trace that seems to indicate that the error happens during the attempt to get the column's distinct values.
A first chance exception of type 'System.NullReferenceException' occurred in Telerik.WinControls.GridView.dll System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.WinControls.UI.RadListFilterMenuProvider.GetDistinctValuesTable(GridViewDataColumn column)
at Telerik.WinControls.UI.RadListFilterMenuProvider.CreateListFilterMenuItems()
at Telerik.WinControls.UI.RadListFilterMenuProvider.CreateFilterMenu()
at Telerik.WinControls.UI.GridHeaderCellElement.FilterFunctionButton_Click(Object sender, EventArgs e)...
Should I be able to have null values in a field bound to a GridViewComboBoxColumn and expect filtering to work properly?
Here are the properties I have set on the grid:
I am creating the column like this:
Am I doing something wrong or is this expected behavior?
I would appreciate any help anyone out there has to offer.
Thanks
A first chance exception of type 'System.NullReferenceException' occurred in Telerik.WinControls.GridView.dll System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.WinControls.UI.RadListFilterMenuProvider.GetDistinctValuesTable(GridViewDataColumn column)
at Telerik.WinControls.UI.RadListFilterMenuProvider.CreateListFilterMenuItems()
at Telerik.WinControls.UI.RadListFilterMenuProvider.CreateFilterMenu()
at Telerik.WinControls.UI.GridHeaderCellElement.FilterFunctionButton_Click(Object sender, EventArgs e)...
Should I be able to have null values in a field bound to a GridViewComboBoxColumn and expect filtering to work properly?
Here are the properties I have set on the grid:
gridCatalog.AllowCellContextMenu = false;
gridCatalog.AllowDeleteRow = false;
gridCatalog.AutoGenerateColumns = false;
gridCatalog.EnableFiltering = true;
gridCatalog.EnableGrouping = false;
gridCatalog.NewRowEnterKeyMode = RadGridViewNewRowEnterKeyMode.EnterMovesToNextCell;
gridCatalog.EnableCustomSorting = false;
gridCatalog.EnableSorting = true;
gridCatalog.MasterTemplate.SelectLastAddedRow = false;
gridCatalog.MasterTemplate.EnableCustomSorting = false;
gridCatalog.MasterTemplate.EnableSorting = true;
gridCatalog.MasterTemplate.ShowHeaderCellButtons = true;
gridCatalog.MasterTemplate.ShowFilteringRow = false;
I am creating the column like this:
var UOMs = from a in dc.vw_UnitOfMeasureLUs
orderby a.UnitOfMeasureName
select a;
GridViewComboBoxColumn colUOM = new GridViewComboBoxColumn();
colUOM.DisplayMember = "UnitOfMeasureName";
colUOM.ValueMember = "UnitOfMeasureID";
colUOM.FieldName = "UnitOfMeasureID";
colUOM.Name = "UnitOfMeasure";
colUOM.HeaderText = "UOM";
colUOM.Width = 80;
colUOM.DataSource = UOMs;
colUOM.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
gridCatalog.MasterTemplate.Columns.Add(colUOM);
Am I doing something wrong or is this expected behavior?
I would appreciate any help anyone out there has to offer.
Thanks
7 Answers, 1 is accepted
0

Richard Slade
Top achievements
Rank 2
answered on 04 Feb 2011, 12:01 AM
Hello,
I have tried out adding a combo column and excel like filtering against a null value and I haven't been able to replicate your issue,
I have prepared a small sample for you to try out. Please can you paste this into a new project and give it a try
Designer File
Form1.cs
Let me know if that helps
Thanks
Richard
I have tried out adding a combo column and excel like filtering against a null value and I haven't been able to replicate your issue,
I have prepared a small sample for you to try out. Please can you paste this into a new project and give it a try
Designer File
namespace
RadGridView_Basic_C
{
partial
class
Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private
System.ComponentModel.IContainer components;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected
override
void
Dispose(
bool
disposing)
{
if
(disposing && (components !=
null
))
{
components.Dispose();
}
base
.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private
void
InitializeComponent()
{
this
.radGridView1 =
new
Telerik.WinControls.UI.RadGridView();
this
.radSpinEditor1 =
new
Telerik.WinControls.UI.RadSpinEditor();
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(
this
.radSpinEditor1)).BeginInit();
this
.SuspendLayout();
//
// radGridView1
//
this
.radGridView1.Location =
new
System.Drawing.Point(0, 0);
this
.radGridView1.Name =
"radGridView1"
;
this
.radGridView1.Size =
new
System.Drawing.Size(457, 510);
this
.radGridView1.TabIndex = 0;
this
.radGridView1.Text =
"radGridView1"
;
//
// radSpinEditor1
//
this
.radSpinEditor1.Location =
new
System.Drawing.Point(196, 517);
this
.radSpinEditor1.Maximum =
new
decimal
(
new
int
[] {
999999,
0,
0,
131072});
this
.radSpinEditor1.Name =
"radSpinEditor1"
;
//
//
//
this
.radSpinEditor1.RootElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
this
.radSpinEditor1.ShowBorder =
true
;
this
.radSpinEditor1.Size =
new
System.Drawing.Size(100, 21);
this
.radSpinEditor1.TabIndex = 1;
this
.radSpinEditor1.TabStop =
false
;
//
// Form1
//
this
.AutoScaleDimensions =
new
System.Drawing.SizeF(6F, 13F);
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this
.ClientSize =
new
System.Drawing.Size(457, 556);
this
.Controls.Add(
this
.radSpinEditor1);
this
.Controls.Add(
this
.radGridView1);
this
.Name =
"Form1"
;
this
.Text =
"Form1"
;
this
.Load +=
new
System.EventHandler(
this
.Form1_Load);
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(
this
.radSpinEditor1)).EndInit();
this
.ResumeLayout(
false
);
this
.PerformLayout();
}
#endregion
private
Telerik.WinControls.UI.RadGridView radGridView1;
private
Telerik.WinControls.UI.RadSpinEditor radSpinEditor1;
}
}
Form1.cs
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
using
Telerik.WinControls;
using
Telerik.WinControls.Data;
using
System.Globalization;
namespace
RadGridView_Basic_C
{
public
partial
class
Form1 : Form
{
private
List<MyDataType> m_myList =
new
List<MyDataType>();
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
this
.radGridView1.AutoGenerateColumns =
false
;
this
.radGridView1.ShowFilteringRow =
false
;
this
.radGridView1.ShowHeaderCellButtons =
true
;
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
m_myList.Add(
new
MyDataType(1,
"10"
));
m_myList.Add(
new
MyDataType(2,
"20"
));
m_myList.Add(
new
MyDataType(3,
"30"
));
m_myList.Add(
new
MyDataType(4,
null
));
radGridView1.DataSource = m_myList;
GridViewDecimalColumn int1Column =
new
GridViewDecimalColumn();
int1Column.Name =
"Int1"
;
int1Column.HeaderText =
"Int1"
;
int1Column.FieldName =
"Int1"
;
this
.radGridView1.Columns.Add(int1Column);
GridViewComboBoxColumn comboColumn =
new
GridViewComboBoxColumn();
comboColumn.Name =
"UnitOfMeasure"
;
comboColumn.HeaderText =
"UnitOfMeasure"
;
comboColumn.FieldName =
"UnitOfMeasure"
;
this
.radGridView1.Columns.Add(comboColumn);
List<UnitOfMeasure> UOM =
new
List<UnitOfMeasure>();
UOM.Add(
new
UnitOfMeasure(
"10"
));
UOM.Add(
new
UnitOfMeasure(
"20"
));
UOM.Add(
new
UnitOfMeasure(
"30"
));
UOM.Add(
new
UnitOfMeasure(
"40"
));
comboColumn.DataSource = UOM;
comboColumn.DisplayMember =
"UOM"
;
comboColumn.ValueMember =
"UOM"
;
radGridView1.DataSource = m_myList;
}
class
MyDataType
{
public
MyDataType()
{ }
public
MyDataType(
decimal
int1,
string
uom)
{
this
.Int1 = int1;
this
.UnitOfMeasure = uom;
}
public
decimal
Int1 {
get
;
set
; }
public
string
UnitOfMeasure {
get
;
set
; }
}
class
UnitOfMeasure
{
public
UnitOfMeasure()
{ }
public
UnitOfMeasure(
string
uom)
{
this
.UOM = uom;
}
public
string
UOM {
get
;
set
; }
}
}
}
Let me know if that helps
Thanks
Richard
0

Anumeha
Top achievements
Rank 1
answered on 04 Feb 2011, 03:30 AM
Thanks for the quick reply Richard. I have tested your code and it does not throw the error when I click the filter icon. However, our UOM table has an ID column and a Name column. I set my combobox column's ValueMember to the UOMID field and the column's DisplayField to the UOMName. When the combobox includes the UOMID field I get an error when I click the filter icon. Here is the updated code:
Thanks again for your help.
public
partial
class
Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
private
void
Form2_Load(
object
sender, EventArgs e)
{
this
.radGridView1.AutoGenerateColumns =
false
;
this
.radGridView1.ShowFilteringRow =
false
;
this
.radGridView1.ShowHeaderCellButtons =
true
;
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewTextBoxColumn colPartNumber =
new
GridViewTextBoxColumn(
"PartNumber"
,
"PartNumber"
);
colPartNumber.HeaderText =
"PartNumber"
;
colPartNumber.Width = 100;
radGridView1.MasterTemplate.Columns.Add(colPartNumber);
GridViewComboBoxColumn comboColumn =
new
GridViewComboBoxColumn();
comboColumn.Name =
"UnitOfMeasure"
;
comboColumn.HeaderText =
"UnitOfMeasure"
;
comboColumn.FieldName =
"UOMID"
;
comboColumn.DataSource = GetUOMTable();
comboColumn.DisplayMember =
"UOMName"
;
comboColumn.ValueMember =
"UOMID"
;
radGridView1.MasterTemplate.Columns.Add(comboColumn);
radGridView1.DataSource = GetPartsTable();
}
private
DataTable GetPartsTable()
{
int
? nullableint = 0;
DataTable dt =
new
DataTable();
DataColumn dcPartNumber =
new
DataColumn(
"PartNumber"
,
typeof
(
string
));
DataColumn dcUOMID =
new
DataColumn(
"UOMID"
, nullableint.GetType());
dt.Columns.Add(dcPartNumber);
dt.Columns.Add(dcUOMID);
DataRow row = dt.NewRow();
row[
"PartNumber"
] =
"Part 1"
;
row[
"UOMID"
] = 1;
dt.Rows.Add(row);
DataRow row2 = dt.NewRow();
row2[
"PartNumber"
] =
"Part 2"
;
row2[
"UOMID"
] = DBNull.Value;
dt.Rows.Add(row2);
return
dt;
}
private
DataTable GetUOMTable()
{
DataTable dt =
new
DataTable();
DataColumn dcUOMID =
new
DataColumn(
"UOMID"
,
typeof
(
int
));
DataColumn dcUOMName =
new
DataColumn(
"UOMName"
,
typeof
(
string
));
dt.Columns.Add(dcUOMID);
dt.Columns.Add(dcUOMName);
DataRow row = dt.NewRow();
row[
"UOMID"
] = 1;
row[
"UOMName"
] =
"Each"
;
dt.Rows.Add(row);
DataRow row2 = dt.NewRow();
row2[
"UOMID"
] = 2;
row2[
"UOMName"
] =
"Feet"
;
dt.Rows.Add(row2);
return
dt;
}
}
Thanks again for your help.
0

Richard Slade
Top achievements
Rank 2
answered on 04 Feb 2011, 08:53 AM
Hi,
Sorry for the delayed reply. I think we must be on different timezones. I haven't run your code yet as I'm not at my development environment (I'll do that as soon as I can and let you know the results). I have looked through the Public Issue Tracking System though to see if there is already a bug that reports this issue. I couldn't find one that is teh same, though it may be the same one as this.
I'll run your code and let you know as soon as I can. In the meantime, please can you confirm which version of RadControls you are using.
Thanks
Richard
Sorry for the delayed reply. I think we must be on different timezones. I haven't run your code yet as I'm not at my development environment (I'll do that as soon as I can and let you know the results). I have looked through the Public Issue Tracking System though to see if there is already a bug that reports this issue. I couldn't find one that is teh same, though it may be the same one as this.
I'll run your code and let you know as soon as I can. In the meantime, please can you confirm which version of RadControls you are using.
Thanks
Richard
0

Richard Slade
Top achievements
Rank 2
answered on 04 Feb 2011, 10:47 AM
Hello,
I've had a look at your code and unless I'm missing something as well, I think that the filter should be able to handle the DBNull value. This should be picked up by the Telerik team that will be able to confirm (or deny) this. If it's the case that this is a bug, then I would expect that
Regards,
Richard
I've had a look at your code and unless I'm missing something as well, I think that the filter should be able to handle the DBNull value. This should be picked up by the Telerik team that will be able to confirm (or deny) this. If it's the case that this is a bug, then I would expect that
Regards,
Richard
0

Anumeha
Top achievements
Rank 1
answered on 04 Feb 2011, 06:22 PM
Thanks for looking at the code Richard. I agree that it looks like it should be ok but it does end up throwing an error when I click the filter icon. I don't even get a chance to choose any of the filtering options. If no one is able to replicate the issue I can submit a support ticket and attach the project.
Thanks
Thanks
0

Richard Slade
Top achievements
Rank 2
answered on 04 Feb 2011, 06:27 PM
Hi,
Apologies if I wasn't clear. Yes, your code looks fine, and yes, I can replicate your issue. Telerik staff are usually very good at keeping an eye on forum posts and it is highly likely that they may have seen this and may be investigating it. However, it may be worth opening a support ticket and Telerik always appreciate it if you can attach a sample project. If you open a support ticket, please also quote this forum link so it's easy for them to track all references to the issue.
hope that helps, but if you need anything else, just let me know.
Regards,
Richard
Apologies if I wasn't clear. Yes, your code looks fine, and yes, I can replicate your issue. Telerik staff are usually very good at keeping an eye on forum posts and it is highly likely that they may have seen this and may be investigating it. However, it may be worth opening a support ticket and Telerik always appreciate it if you can attach a sample project. If you open a support ticket, please also quote this forum link so it's easy for them to track all references to the issue.
hope that helps, but if you need anything else, just let me know.
Regards,
Richard
0
Hello guys,
I managed to reproduce the described exception. It is caused because of an omission in our method of getting distinct values if there is a DBNull type in the column. We will address this issue in the next release. I am adding this issue in our public bug tracking system (PITS)
Anumeha, I have updated your Telerik points for bringing our attention to this issue. Do not hesitate to contact us again if you have any other questions.
Kind regards,
Martin Vasilev
the Telerik team
I managed to reproduce the described exception. It is caused because of an omission in our method of getting distinct values if there is a DBNull type in the column. We will address this issue in the next release. I am adding this issue in our public bug tracking system (PITS)
Anumeha, I have updated your Telerik points for bringing our attention to this issue. Do not hesitate to contact us again if you have any other questions.
Kind regards,
Martin Vasilev
the Telerik team