I had a lot of problems with the bound combobox on a tabpage when
using the currency manager. However i didnt use the CM to move from
record to record, just used it to refresh the dataset so it knew it
had changed.
If you are using VS 2003, then i think the problem is easier to solve,
as you can use the DropDown style and then bind to the Text property.
Then you just need to handle the keyboard entry so the user cannot
change the value (so it acts like DropDownList). I created a custom
control in the end for it which did just that and then used my combo
box rather than the system.windows.forms one
If you are thinking of going this route then the class was as follows:
Public Class BindableCombo
Inherits System.Windows.Forms.ComboBox
Private m_bIsReadonly As Boolean = True
Public Property IsReadonly() As Boolean
Get
Return m_bIsReadonly
End Get
Set(ByVal Value As Boolean)
m_bIsReadonly = Value
End Set
End Property
Private Sub BindableCombo_KeyDown(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If m_bIsReadonly Then
e.Handled = True
End If
End Sub
Private Sub BindableCombo_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If m_bIsReadonly Then
e.Handled = True
End If
End Sub
End Class
I think there are some other things you have to handle, but you get
the idea.
Now, if you are using VS.NET 2002, like myself, then this wont work as
the above code for handling the keystrokes does not work in the combo
in vs.net 2002!
I ended up with a pretty strange workaround, but one that works. I
basically add a simple bind and a complex bind to each combobox (i
noticed this becuase one of the cbo's i had was working fine. It was a
list of users which i read from the database so the user could select
one. The list was complex bound to the cbo and the user selection was
simple bound).
I create a dummy datatable, which in my case was created from the
items in the combo (as they were hard coded and added in using the
designer) as follows:
Dim dt As New DataTable("List")
Dim col As DataColumn = New DataColumn("Description", GetType(String))
dt.Columns.Add(col)
Dim dr As DataRow
Dim ob As Object
For Each ob In cbo.Items
dr = dt.NewRow()
dr("Description") = CType(ob, String)
dt.Rows.Add(dr)
Next ob
Then i cleared the items list:
cbo.Items.Clear()
Then added both bindings as follows (note that i bind to the
'SelectedValue' column):
cbo.DataBindings.Add("SelectedValue", datasource, datamember)
cbo.DataSource = dt
cbo.DisplayMember = "Description"
cbo.ValueMember = "Description"
The "Description" is from the dummy dt i created above. The datasource
and datamamber are what they would be normally.
I actually created a function to do this as i had many cbo boxes on
each screen.
In addition to this, if you are still awake, i had to add some code
depending on if the cbo was on the first tab that was displayed on the
screen or not.
After loading the screen and binding each control (in the code), i
refresh the CM.
This all seems to work for me, i can even have the cbo drop style set
to DropDownList so there is no problem with the user editing the
value.
One other thing to mention that i noticed that you may or may not be
having poblems with is that i had to set the cm.position to itself
before checking if the dataset had changed.
I hope all of this helps and is relevant, it sounds like you were
having similar problems to myself, so i thought i'd share this lot
with you. It took a lot of head scratching to get to where i am
MB
[quoted text, click to view] "Mike V." <anonymous@discussions.microsoft.com> wrote in message news:<825001c477ed$77e1d5a0$a401280a@phx.gbl>...
> Same problem here, and you don't see any books explaining
> how to handle nulls in comboboxes and which properties to
> bind to.
> This is exactly what the Format/Parse events are for. If
> you take them out you'll have to manipulate the results in
> code in code.
>
> Let me know when you find a solution for combobox nulls
> when dates are involved or when strings are involved.
>
> Mike
>
>
> >-----Original Message-----
> >Take out the parse/format as a test. This is where ALL my
> databinding
> >problems have occured. It doesn't seem to fire errors the
> same way - so
> >you'll never see that the data is a problem.
> >
> >
> >
> >"njp" <npost@systek.com> wrote in message
> >news:eDI2ecCcEHA.3148@TK2MSFTNGP10.phx.gbl...
> >> BlankHi,
> >>
> >> So much struggle and wasted time (days). I'm having a
> terrible time
> getting
> >> bound comboboxes placed on tab pages to behave
> correctly. I can't get null
> >> values to display when navigating between records. The
> previous values
> >> display instead of null. Also, the binding.format event
> is not firing.
> >>
> >> Here's a *summary* of the code involved (extracted from
> various
> >> subroutines). Although I have many fields, this is the
> code for just one
> of
> >> them. It's a combobox on a tab page which is on another
> tab page. The
> >> combobox has items listed in its items property. The
> style is set as
> >> DropDown since I read that DropDownList (my desire)
> causes problems.
> >>
> >> I appreciate any help you can offer! I can't find
> anything else on MS or
> via
> >> google that is helpful. Regards, NJ
> >>
> >> 1) daModemPort.Fill(DsTerminal1, "tblModem")
> >>
> >> 2) Dim tempB As Binding
> >> tempB = New Binding("SelectedItem",
> DsTerminal1, "tblModem.mCodeType")
> >> AddHandler tempB.Format, AddressOf CheckForNull
> >> AddHandler tempB.Parse, AddressOf CheckForNull2
> >> cboModCodingType.DataBindings.Add(tempB)
> >> (i assume it's ok to bind to SelectedItem. i had other
> problems when i
> used
> >> other properties.)
> >>
> >> 3) cmModemPort = CType(BindingContext
> (DsTerminal1, "tblModem"),
> >> CurrencyManager)
> >> AddHandler cmModemPort.PositionChanged, AddressOf
> >> cmModemPort_PositionChanged
> >> (didn't incl. code from PositionChanged routine
> since it doesn't
> >> seem relevant)
> >>
> >> 4) tpModem.BindingContext = Me.BindingContext
> >> (I read in the binding "bible" referenced in
> another post that I
> >> should have the above code for the tab page to get
> around an error.)
> >>
> >> 5) 2 records are in db. there is a value in rec 1 for
> the combobox and
> null
> >> in rec 2. dataset reflects this as well. when i first
> go from rec 1 to rec
> 2
> >> the combobox correctly displays nothing. however if i
> go back to rec 1 and
> >> back to rec 2, the value from rec 1 shows in rec 2's