Hi,
But the "Value" parameter is System.dBNull. ¿why? .
Thanks,
| private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) |
| { |
| if (sender is GridCheckBoxCellElement) |
| { |
| if ((bool)((GridCheckBoxCellElement)e.CellElement).Value == true) |
| { |
| e.CellElement.RowElement.ForeColor = Color.Red; |
| } |
| } |
| } |
But the "Value" parameter is System.dBNull. ¿why? .
Thanks,
3 Answers, 1 is accepted
0
Hi Fernan,
I suppose that the cell value is DBNull, because of its data source value. I have changed your code because if you want to change the fore color of the cell you should set its property (not the row's property ForeColor). You can use the following code snippet:
A bit off topic, please ask the person who has purchased our controls in your company to add you as a License Developer to the purchase. This will give you full access to the products your company has purchased, to our downloads section, and to our support ticketing system. Additionally, all your questions will be reviewed according to the license you have. More information on License Developers you can find here: www.telerik.com/account/faqs.aspx.
Kind regards,
Svett
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
I suppose that the cell value is DBNull, because of its data source value. I have changed your code because if you want to change the fore color of the cell you should set its property (not the row's property ForeColor). You can use the following code snippet:
private void radGridView_CellFormatting(object sender, CellFormattingEventArgs e){ GridViewDataRowInfo dataRow = e.CellElement.RowInfo as GridViewDataRowInfo; GridViewDataColumn dataCol = e.CellElement.ColumnInfo as GridViewDataColumn; if (dataRow == null || dataCol == null) { return; } object value = dataRow.Cells["Bool"].Value; if (value != null && Convert.ToBoolean(value)) { e.CellElement.ForeColor = Color.Red; } else { e.CellElement.ResetValue(LightVisualElement.ForeColorProperty); }}A bit off topic, please ask the person who has purchased our controls in your company to add you as a License Developer to the purchase. This will give you full access to the products your company has purchased, to our downloads section, and to our support ticketing system. Additionally, all your questions will be reviewed according to the license you have. More information on License Developers you can find here: www.telerik.com/account/faqs.aspx.
Kind regards,
Svett
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
0
Fernan
Top achievements
Rank 1
answered on 05 May 2010, 08:13 AM
Hi, thanks you.
Yes, I am using data source values. I put your code and the error is the same: the value is dbNull:
I want to change the row's forecolor and row's backcolor when the user set to true the checkbox cell.
Thanks,
Yes, I am using data source values. I put your code and the error is the same: the value is dbNull:
| System.InvalidCastException was unhandled |
| Message="No se puede convertir un objeto DBNull en otros tipos." |
| Source="mscorlib" |
| StackTrace: |
| en System.DBNull.System.IConvertible.ToBoolean(IFormatProvider provider) |
| en System.Convert.ToBoolean(Object value) |
| en GIREv2.Controls.BaseForm.radGridView1_CellFormatting(Object sender, CellFormattingEventArgs e) en E:\Proyectos\RadGridFilterXLS\RadGridFilterXLS\Controls\BaseForm.cs:lÃnea 1885 |
| en Telerik.WinControls.UI.RadGridView.OnCellFormatting(Object sender, CellFormattingEventArgs e) |
| en Telerik.WinControls.UI.RadGridView.CallCellFormatting(Object sender, CellFormattingEventArgs e) |
| en Telerik.WinControls.UI.GridDataCellElement.UpdateInfoCore() |
| en Telerik.WinControls.UI.GridCellElement.UpdateInfo() |
| en Telerik.WinControls.UI.GridRowElement.UpdateInfo() |
| en Telerik.WinControls.UI.GridDataRowElement.UpdateInfo() |
| en Telerik.WinControls.UI.GridRowElement.Initialize(GridViewRowInfo rowInfo) |
| en Telerik.WinControls.UI.GridTableBodyElement.UpdateRow(Int32 position, GridViewRowInfo rowInfo) |
| en Telerik.WinControls.UI.GridTableBodyElement.UpdateRowElements(IEnumerable`1 rows, RectangleF clientRect, Single& y, Int32& position, Int32 startIndex, Int32& added, Single left, Single width) |
| en Telerik.WinControls.UI.GridTableBodyElement.ArrangeOverride(SizeF finalSize) |
| en Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect) |
| en Telerik.WinControls.RadElement.Arrange(RectangleF finalRect) |
| en Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout() |
| en Telerik.WinControls.RadElement.UpdateLayout() |
| en Telerik.WinControls.UI.GridTableElement.EnsureRowVisible(GridViewRowInfo rowInfo) |
| en Telerik.WinControls.UI.GridTableElement.UpdateCurrentPosition() |
| en Telerik.WinControls.UI.GridViewInfo.SetCurrentRow(GridViewRowInfo row, Boolean setPosition, Boolean shift, Boolean control, Boolean rightMouseButton) |
| en Telerik.WinControls.UI.BaseGridNavigator.SelectNextRow(Int32 step, Boolean shift, Boolean control) |
| en Telerik.WinControls.UI.BaseGridNavigator.SelectNextRow(Int32 step, Boolean shift, Boolean control) |
| en Telerik.WinControls.UI.BaseGridBehavior.EnterOnNewRow() |
| en Telerik.WinControls.UI.BaseGridBehavior.ProcessEnterKey(KeyEventArgs keys) |
| en Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys) |
| en Telerik.WinControls.UI.BaseGridBehavior.ProcessKeyDown(KeyEventArgs keys) |
| en Telerik.WinControls.UI.RadTextBoxEditorElement.OnKeyDown(KeyEventArgs e) |
| en Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyDown(Object sender, KeyEventArgs e) |
| en System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) |
| en System.Windows.Forms.Control.WmKeyChar(Message& m) |
| en System.Windows.Forms.Control.WndProc(Message& m) |
| en Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message) |
| en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) |
| en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) |
| en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) |
| en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) |
| en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) |
| en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) |
| en GIREv2.Program.Main() en E:\Proyectos\RadGridFilterXLS\RadGridFilterXLS\Program.cs:lÃnea 27 |
| en System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) |
| en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() |
| en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) |
| en System.Threading.ThreadHelper.ThreadStart() |
| InnerException: |
I want to change the row's forecolor and row's backcolor when the user set to true the checkbox cell.
Thanks,
0
Hi Fernan,
The issue occurs due to DBNull.Value. You should change my previous code snippet to check for it:
Let us know if you have further issues.
Greetings,
Svett
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
The issue occurs due to DBNull.Value. You should change my previous code snippet to check for it:
private void radGridView_CellFormatting(object sender, CellFormattingEventArgs e){ GridViewDataRowInfo dataRow = e.CellElement.RowInfo as GridViewDataRowInfo; GridViewDataColumn dataCol = e.CellElement.ColumnInfo as GridViewDataColumn; if (dataRow == null || dataCol == null) { return; } object value = dataRow.Cells["Bool"].Value; if (value != null && value != DBNull.Value && Convert.ToBoolean(value)) { e.CellElement.ForeColor = Color.Red; } else { e.CellElement.ResetValue(LightVisualElement.ForeColorProperty); }}Let us know if you have further issues.
Greetings,
Svett
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.