I have a DataTable with a integer field called SortOrder.
This table is loaded with and XML file.
I have this table in a DataView and I set the RowFilter to filter some row,
then I change the SortOrder, set the Sort property to "SortOrder".
This works fine the first 20 to 50 times. Then I get this error.
This error does not occur if I do not set the Sort property to SortOrder.
If I set the Sort property to another column or blank the error never
occures.
================================================== =======================
Additional information: Object reference not set to an instance of an
object.
Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at
System.Data.DataRowView.System.ComponentModel.IDat aErrorInfo.get_Error()
at System.Windows.Forms.DataGridRow.PaintHeader(Graph ics g, Rectangle
visualBounds, Boolean alignToRight, Boolean rowIsDirty)
at
System.Windows.Forms.DataGridRelationshipRow.Paint HeaderInside(Graphics g,
Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
at System.Windows.Forms.DataGridRelationshipRow.Paint Header(Graphics g,
Rectangle bounds, Boolean alignToRight, Boolean isDirty)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventAr gs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason,
Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Maxine.frmMain.Main() in c:\ab-visual studio
projects\maxinexml-2\formmain.cs:line 851
The program '[1052] Maxine.exe' has exited with code 0 (0x0).
================================================== ==========================
======
Here is a code snippett.
//================================================== ========================
====
// update the DataView from the songs that are in the list;
// the dataview will show them in the correct order
public void UpdateView()
{
if (dview == null)
{ return; } // no view so exit
int sort = 1;
if (al.Count == 0) // no songs in play list
{
dview.RowFilter = "theIndex = -1"; // no
songs will pass this filter
return;
}
String filter = "";
//dset.Songs.AcceptChanges();
foreach (String s in al)
{
Debug.WriteLine("Sort Number " + s);
filter = filter + "theIndex = '" + s + "' OR
";
DataRow dr =
dset.Songs.FindBytheIndex(Convert.ToInt32(s));
//DataRow dr = dview.Table.;
if (dr != null)
{
try
{
dr.BeginEdit();
dr["SortOrder"] = sort; //
sort order field on songs is the order
dr.EndEdit();
// that they will be displayed (and played)
if (dr.HasErrors)
{
Debug.WriteLine("Got and error in edit"); }
dset.Songs.AcceptChanges();
sort++;
}
catch(Exception e1)
{
Debug.WriteLine("Error
trying to write a sort order" + e1.Message);
}
}
else
{
Debug.WriteLine("Got a null pointer
for: " + s);
}
}
//dset.Songs.AcceptChanges();;
filter = filter.Remove(filter.Length-4,4); //
remove the last "OR"
Debug.WriteLine("Filter: " + filter);
try
{
dview.RowFilter = filter;
dview.Sort = "SortOrder";
}
catch(Exception e)
{
Debug.WriteLine("Got an error doing a sort:
" + e.Message);
}