DataGrid Question:

  • Thread starter Thread starter consumer62000
  • Start date Start date
C

consumer62000

I am trying to decompile datagrid. Here is my problem
I want to know when does the datagrid create (subscribe to) the handler
of ListChanged event.

I have my own collection attached to the datagrid and I want to remove
an item from the bound collection from a backend thread. But when I do
that I get the following error( see at the end of this message )

I believe I can prevent this problem if I somehow marshal the call to
the control containing the grid. Remember I am tring to remove an
object from the collection in the backend thread in the business object
and I don't have access to the user interface thread.

2 questions
1. How can I fix the problem?
2. Where in datagrid is the ListChanged handler coded. I used Anakrino
to decompile the code.
Thanks






=============================================================
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IndexOutOfRangeException: No value at index 9.
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g,
Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
at
System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics
g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean
isDirty)
at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(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(PaintEventArgs pe)
at
System.Windows.Forms.Control.PaintWithErrorHandling(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(Message& m)
 
I am not well versed enough in Windows Forms to point directly to an answer,
but I can get you on the right track.

First, I would try this tool instead:
http://www.aisto.com/roeder/dotnet/

A good add-in for Reflector found here:
http://www.denisbauer.com/NETTools/FileDisassembler.aspx

This is better than Anakrino.

To see where events are wired up, examine the class definition and the
constructor:

Class DEF for System.Windows.Forms.DataGrid
-------------------------------------------------------

// Events
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnNavigationModeChangedDescr")]
public event EventHandler AllowNavigationChanged;
[SRCategory("CatAction"), SRDescription("DataGridBackButtonClickDescr")]
public event EventHandler BackButtonClick;
[SRDescription("DataGridOnBackgroundColorChangedDescr"),
SRCategory("CatPropertyChanged")]
public event EventHandler BackgroundColorChanged;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler BackgroundImageChanged;
[SRDescription("DataGridOnBorderStyleChangedDescr"),
SRCategory("CatPropertyChanged")]
public event EventHandler BorderStyleChanged;
[SRDescription("DataGridOnCaptionVisibleChangedDescr"),
SRCategory("CatPropertyChanged")]
public event EventHandler CaptionVisibleChanged;
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnCurrentCellChangedDescr")]
public event EventHandler CurrentCellChanged;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler CursorChanged;
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnDataSourceChangedDescr")]
public event EventHandler DataSourceChanged;
[SRDescription("DataGridOnFlatModeChangedDescr"),
SRCategory("CatPropertyChanged")]
public event EventHandler FlatModeChanged;
[SRDescription("DataGridNavigateEventDescr"), SRCategory("CatAction")]
public event NavigateEventHandler Navigate;
[SRCategory("CatAction"), SRDescription("DataGridNodeClickEventDescr")]
internal event EventHandler NodeClick;
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnParentRowsLabelStyleChangedDescr")]
public event EventHandler ParentRowsLabelStyleChanged;
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnParentRowsVisibleChangedDescr")]
public event EventHandler ParentRowsVisibleChanged;
[SRCategory("CatPropertyChanged"),
SRDescription("DataGridOnReadOnlyChangedDescr")]
public event EventHandler ReadOnlyChanged;
protected event EventHandler RowHeaderClick;
[SRDescription("DataGridScrollEventDescr"), SRCategory("CatAction")]
public event EventHandler Scroll;
[SRDescription("DataGridDownButtonClickDescr"), SRCategory("CatAction")]
public event EventHandler ShowParentDetailsButtonClick;
[EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
public event EventHandler TextChanged;

Constructor
-------------
this.currentChangedHandler = new
EventHandler(this.DataSource_RowChanged);
this.positionChangedHandler = new
EventHandler(this.DataSource_PositionChanged);
this.itemChangedHandler = new
ItemChangedEventHandler(this.DataSource_ItemChanged);
this.metaDataChangedHandler = new
EventHandler(this.DataSource_MetaDataChanged);
this.dataGridTableStylesCollectionChanged = new
CollectionChangeEventHandler(this.TableStylesCollectionChanged);
this.dataGridTables.CollectionChanged +=
this.dataGridTableStylesCollectionChanged;
this.SetDataGridTable(this.defaultTableStyle, true);
this.backButtonHandler = new EventHandler(this.OnBackButtonClicked);
this.downButtonHandler = new
EventHandler(this.OnShowParentDetailsButtonClicked);
this.caption.BackwardClicked += this.backButtonHandler;
this.caption.DownClicked += this.downButtonHandler;

The decompiler will allow you to completely decompile the source and use
your implementation to figure out how to override.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top