Black Friday = Pricewatch Bekijk onze selectie van de beste Black Friday-deals en voorkom een miskoop.

[C#] Custom DataGridView re-bind "zichzelf" een paar keer

Pagina: 1
Acties:

  • Knakker
  • Registratie: April 2000
  • Laatst online: 15-11 19:45
Ik heb een heel gek probleem. Ik heb een custom datagridview voor mijn applicatie gemaakt (tekent zelf alles etc). Tijdens de (interne) initialisatie procedure worden een hele hoop dingen ingesteld, waaronder de hoogte en HeaderCell.Value van elke rij.

Nu wil het geval dat op moment van tekenen de rijhoogte weer terug is naar z'n standaardwaarde en ook de HeaderCell.Value is weer leeg. Na een tijdje grondig doorspitten van mijn datagridview blijkt dat ergens, tussen mijn eigen initialisatie en het tekenen van de control, de datatable opnieuw gebind wordt - meerdere malen zelfs, zo kwam ik achter (via het OnDataMemberChanged event). Dit verklaart in ieder geval waarom de standaard layout instellingen weer terug zijn naar hun standaard waarden, maar over het waarom en hoe ik dat moet tegengaan tast ik in het duister.

Dus: in mijn hele klasse wordt de base.DataSource maar één keer ingesteld (heb via een lelijke messagebox gecontroleerd dat dat ook maar écht één keer gebeurd) en toch blijkt uit het OnDataMemberChanged event dat er meerdere malen data gebind wordt nádat alles geinitialiseerd is.

Wie heeft een idee hoe ik dit debuggen aan zou kunnen pakken om erachter te komen waar en waarom dit gebeurd? Alvast bedankt :)

Geef mij maar een Warsteiner.


  • D-Raven
  • Registratie: November 2001
  • Laatst online: 16-10 10:47
Je geeft zelf al het antwoord. OnDataMemberChanged event. Ik zou eens gaan kijken wat de voorwaarden zijn van het triggeren van dit ding, en dan eens gaan kijken hoe het komt dat dit zo vaak voorkomt.
Zit je misschien in je control op de datasource zelf dingen te wijzigen ofzow ? Kan me voorstellen dat als je een value veranderd ofzow dat dan dat event getriggerd wordt.

  • sopsop
  • Registratie: Januari 2002
  • Laatst online: 15-11 12:29

sopsop

[v] [;,,;] [v]

Kun je als je een breakpoint zet op OnDataMemberChanged de callstack niet eens uitpluizen?

  • Knakker
  • Registratie: April 2000
  • Laatst online: 15-11 19:45
Ik heb het OnBindingContextChanged event bij de tweede keer laten stoppen en de call stack gekopieerd. Ik word er amper wijs uit, vooral omdat een "CreateControl()" zonder dat het zegt wat het aan het maken is mij weinig zegt.

Bovenaan staat de laatste (correcte, geverifieerde) actie, en onderaan wanneer ik het programma stop.

Wie kan me verder op weg helpen?

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Prospect.exe!Prospect.GUI.Controls.Main.Panel.LoadControl(System.Windows.Forms.Control C = {Prospect.GUI.Main.Data}) Line 35
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control value = {Prospect.GUI.Main.Data}) + 0x147 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() + 0x24 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x12a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x8a bytes
System.Windows.Forms.dll!System.Windows.Forms.TabControl.CreateHandle() + 0x7a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle() + 0x125 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp) + 0x225 bytes
System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.Runtime.InteropServices.HandleRef hWndParent, System.Runtime.InteropServices.HandleRef hMenu, System.Runtime.InteropServices.HandleRef hInst, object pvParam) + 0x3c bytes
[Managed to Native Transition]
[Native to Managed Transition]
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 1, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.TabControl.WndProc(ref System.Windows.Forms.Message m) + 0x1b6 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x2e7 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmCreate(ref System.Windows.Forms.Message m) + 0x43 bytes
System.Windows.Forms.dll!System.Windows.Forms.TabControl.OnHandleCreated(System.EventArgs e) + 0x247 bytes
System.Windows.Forms.dll!System.Windows.Forms.TabControl.UpdateTabSelection(bool updateFocus = false) + 0xe5 bytes
System.Windows.Forms.dll!System.Windows.Forms.TabPage.Visible.set(bool value) + 0x11 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.SetVisibleCore(bool value = true) + 0x156 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() + 0x24 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x12a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x12a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x12a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x12a bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible = false) + 0x15f bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.SetParentHandle(System.IntPtr value) + 0xba bytes
[Managed to Native Transition]
[Native to Managed Transition]
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 24, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.WndProc(ref System.Windows.Forms.Message m) + 0xfe bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x2b6 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmShowWindow(ref System.Windows.Forms.Message m) + 0x98 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() + 0x87 bytes
Prospect.exe!Prospect.GUI.Base.DataGridViewEx.OnBindingContextChanged(System.EventArgs e = {System.EventArgs}) Line 76 + 0x4a bytes

Geef mij maar een Warsteiner.