Hi,
i wanted to update DataTable and show the data in a grid
i update DataTable in a timer with the interval of 1 second
it updates successfully but when i drag the column header and the update timer ticks the following error occurs
here is my code:
i wanted to update DataTable and show the data in a grid
i update DataTable in a timer with the interval of 1 second
it updates successfully but when i drag the column header and the update timer ticks the following error occurs
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=Telerik.WinControls.GridView
StackTrace:
at Telerik.WinControls.UI.RadGridViewDragDropService.GetDragImageHint(ContentAlignment textAlignment, Bitmap hintImage, RectangleF textRectangle, Int32 hintImageWidth)
at Telerik.WinControls.UI.GridHeaderCellElement.GetDragHintCore()
at Telerik.WinControls.RadItem.Telerik.WinControls.ISupportDrag.GetDragHint()
at Telerik.WinControls.RadDragDropService.PrepareContext()
at Telerik.WinControls.RadDragDropService.HandleMouseMove(Point mousePos)
at Telerik.WinControls.UI.RadGridViewDragDropService.HandleMouseMove(Point mousePosition)
at Telerik.WinControls.RadDragDropService.Telerik.WinControls.IMessageListener.PreviewMessage(Message& msg)
at Telerik.WinControls.RadMessageFilter.NotifyGetMessageEvent(Message& msg)
at Telerik.WinControls.RadMessageFilter.GetMessageHookProc(Int32 code, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.GetMessageW(MSG& msg, HandleRef hWnd, Int32 uMsgFilterMin, Int32 uMsgFilterMax)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at RadControlsWinFormsApp1.Program.Main() in Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
here is my code:
private
void
RadRibbonForm1_Load(
object
sender, EventArgs e)
{
DataTable Data =
new
DataTable();
Data.Columns.Add(
"field1"
);
Data.Columns.Add(
"field2"
);
Data.Columns.Add(
"field3"
);
Data.Columns.Add(
"field4"
);
Data.Columns.Add(
"field5"
);
Data.Columns.Add(
"field6"
);
Data.Columns.Add(
"field7"
);
Data.Columns.Add(
"field8"
);
Data.Columns.Add(
"field9"
);
radGridView1.DataSource = Data;
}
void
fillData()
{
lock
(Data)
{
Data.BeginLoadData();
if
(adapter.SelectCommand.Connection.State == ConnectionState.Closed)
adapter.SelectCommand.Connection.Open();
SqlDataReader reader = adapter.SelectCommand.ExecuteReader();
try
{
while
(reader.Read())
{
var v1 = reader.GetInt64(0);
var v2 = reader.GetInt32(1);
var v3 = reader.GetDouble(2);
var v4 = reader.GetDouble(3);
var v5 = reader.GetString(4);
var v6 = reader.GetString(5);
var v7 = reader.GetFloat(6);
var v8 = reader.GetFloat(7);
var v9 = reader.GetInt32(8);
Data.LoadDataRow(
new
object
[] { v1, v2, v3, v4, v5, v6, v7, v8, v9 },
false
);
}
Data.EndLoadData();
reader.Close();
DataRow[] deletedrows = Data.Select(
string
.Empty,
string
.Empty, DataViewRowState.Unchanged);
foreach
(DataRow item
in
deletedrows)
item.Delete();
Data.AcceptChanges();
}
catch
(Exception)
{
Data.EndLoadData();
reader.Close();
}
}
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
fillData();
this
.radGridView1.MasterTemplate.Refresh(
null
);
}