Re: Binding.Format event with ComboBox

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Krueger [MSFT] (a-tkrueg_at_online.microsoft.com)
Date: 02/08/05


Date: Mon, 7 Feb 2005 17:13:37 -0800


I'm looking into this. I did find that the SelectedValue Binding does fire
when the control loses focus, but it does not fire when an item is selected.
So that confirms your findings, I don't know if it will be possible or not.

-- 
Tom Krueger
My Blog - http://weblogs.asp.net/tom_krueger
Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility
This posting is provided "as is" with no warranties and confers no rights.
"Kyle Baley" <KyleBaley@discussions.microsoft.com> wrote in message 
news:AE00D4D6-FCD6-459A-9A0C-6B3EC3499055@microsoft.com...
> I'm binding a ComboBox's SelectedValue property to a datasource and using 
> a
> custom Format event. The problem is that the format event never fires. 
> Here's
> some sample code that demonstrates this (create a form with a combobox on 
> it):
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
>        Dim t As DataTable = New DataTable
>
>        t.Columns.Add(New DataColumn("ID",
> System.Type.GetType("System.Int32")))
>        t.Columns.Add(New DataColumn("Name",
> System.Type.GetType("System.String")))
>        t.Rows.Add(New Object() {1, "One"})
>        t.Rows.Add(New Object() {2, "Two"})
>        t.Rows.Add(New Object() {3, "Three"})
>
>        ComboBox1.DataSource = t
>        ComboBox1.DisplayMember = "Name"
>        ComboBox1.ValueMember = "ID"
>
>        getBinding()
>
>    End Sub
>
>    Public Sub getBinding()
>        Dim t As DataTable = New DataTable
>        t.Columns.Add("EntityID", System.Type.GetType("System.String"))
>        t.Columns.Add("NumberID", System.Type.GetType("System.Int32"))
>        t.Rows.Add(New Object() {"123", 2})
>
>        Dim b As Binding = New Binding("SelectedValue", t, "NumberID")
>        AddHandler b.Format, AddressOf Format_Event
>        ComboBox1.DataBindings.Add(b)
>
>    End Sub
>
>    Private Sub Format_Event(ByVal sender As Object, ByVal e As
> ConvertEventArgs)
>        MsgBox("Moo")
>    End Sub
>
> As it standards, Format_Event will never run (although the combobox is
> properly bound and it's value is set to 2). Also note that if you change 
> the
> binding so that it binds to the SelectedIndex property, the Format event
> fires as expected.
>
> So the question is, why doesn't the Format event fire when I add a binding
> to a ComboBox's SelectedValue property?
>
> Apologies if this has been answered already. I've found similar questions
> asked on various newsgroups but haven't seen any solutions. 


Relevant Pages

  • Re: ComboBox - How to stop firing Select Index Event on Load
    ... > Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ... > I am binding a dataset to a ComboBoxwhich causes the ... > don't want to fire this code when binding the data to the combobox. ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: Binging custom objects to the DataGridViewComboBoxColumn
    ... Apparently the combobox column for a DGV binds to ... SelectedValue, so you have to make your own ComboBoxItemColumn type. ... object when binding to a textbox column. ... I haven't seen this kind of functionality from the DataGridView. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: BindingSource.Add raises error
    ... > I have a set of controls on a form that are bound to an underlying object ... If you bind to "SelectedValue" and you can not move out of the ComboBox, ... > Bart Mermuys wrote: ... >> exactly binding and how... ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: bind question - is there a not modifier?
    ... your problem is that you have a binding ... on a canvas item and a slightly different binding on the canvas. ... canvas man page documents the fact that both of these bindings will fire. ... And I now understand the paragraph in bind on multiple ...
    (comp.lang.tcl)
  • Re: Binding.Format event with ComboBox
    ... Parse on the SelectedValue binding of a ComboBox to convert between DBNull ... The Format event would not be fired when the form was ...
    (microsoft.public.dotnet.framework.windowsforms)