Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Binding.Format event with ComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kyle Baley - 31 Jan 2005 16:57 GMT
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.
Tom Krueger [MSFT] - 08 Feb 2005 01:13 GMT
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.

Signature

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.

> I'm binding a ComboBox's SelectedValue property to a datasource and using
> a
[quoted text clipped - 52 lines]
> Apologies if this has been answered already. I've found similar questions
> asked on various newsgroups but haven't seen any solutions.
kaborka - 26 Apr 2005 18:48 GMT
Attn Tom:  Did you ever follow up on this.  I also tried to use Format and
Parse on the SelectedValue binding of a ComboBox to convert between DBNull
and a default value.  The Format event would not be fired when the form was
populated from the db.

At dotnet247 website, I saw a post from "Ying-Shen Yu [MSFT] Microsoft
community Support" stating Format is not supported for a ComboBox in .NET
v1.1.  (See:
http://www.dotnet247.com/247reference/msgs/46/233079.aspx).  Is there any fix?

> 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.
[quoted text clipped - 56 lines]
> > Apologies if this has been answered already. I've found similar questions
> > asked on various newsgroups but haven't seen any solutions.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.