Alright, I answered another question in a newsgroup, but the question posed, while technical, gets an A+ for honesty. It starts like this:
I'm tearing my hair out at the moment trying to work out why the above
isn't working!
Now, the "above" is that a custom UserControl in a VSTO task pane does not do databinding as expected. It's easy to repro, and it can be repro'd in a simple WinForm app. So, I dedicate this blog entry to Keni (the ng poster). Get your Minoxidil, and here are the steps:
- Create a WinForm app
- Add new custom control
- Add a new datasource (Northwind's Regions table is fine)
- Drag the table form the Datasource window onto the custom control. A datagrid should appear on it.
- Build
- Drag custom control from toolbox to your startup WinForm
- F5
What you will notice is that the custom control's grid never fills. I initially thought this was a bug, because if you follow the same steps, but instead of adding a custom control and adding the grid to that control, just add the grid directly on the WinForm and F5. The grid will fill.
Well, it's by design. The reason actually does make sense. There was an internal bug filed on this earlier this year, but it was resolved as "by design". Here's the skinny:
It all comes down to complexities that would arise if we had the code automatically call the fill method of the table's adaptor when the control loads. These complexities under-the-hood do not present themselves in the much simpler arrangement of straight-forward WinForm databinding. To avoid these, we do not put the code in there to call the Fill method. You should add your own custom procedure to fill the dataset to your control. Call that method from an event in the host form or elsewhere in the app. Do not fill the dataset when the control loads.
For example, here's my simple procedure to fill the dataset:
Public Sub FillDS()
Me.RegionTableAdapter.Fill(Me.RegionDataSet._Region)
End Sub
Here's the code I use to call this procedure in the control:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.UserControl11.FillDS()
End Sub
This post was on the microsoft.public.vsnet.vstools.office news group.
Rock Thought for the Day: Heard Killling Joke's song 'Wardance" off their 2003 self-titled CD. Folks, if Green Day is your best connection to punk rock, uh...it's time to dig a little deeper. Iggy Pop's "Lust for Life", anything by the Ramones, and the Clash's "White Riot" just for starters. I caught onto these songs in the seventies as a kid, and they reached my soul.
Rock On