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 combobox. because of
bugs listed in the MS knowledge base: 327244, 327555, 814346 I implemented
the following to hopefully correct the null problem but I can't get the
Format event to fire for the combobox's binding. according to the
documentation it should fire when the currency manager's position changes. i
know the position is changing.
Private Sub CheckForNull(ByVal sender As Object, ByVal cevent As
ConvertEventArgs)
Try
Debug.WriteLine("inside check for nulls")
Debug.WriteLine("cevent.getType = " & cevent.GetType.ToString & _
" object = " & CType(CType(sender, Binding).Control,
ComboBox).Name)
If cevent.Value Is System.DBNull.Value Or cevent.Value = "" Then
CType(CType(sender, Binding).Control, ComboBox).SelectedIndex
= -1
CType(CType(sender, Binding).Control, ComboBox).SelectedIndex = -1
End If
Catch ex As Exception
Debug.WriteLine("Null Check Error:" & ex.Message)
End Try
End Sub
Of course there is lots more code, fields, and field types and the above
seems so standard but I just can't get past the problems. Would it be better
to have a typed dataset by using the designer's dataset widget?
njp - 22 Jul 2004 21:59 GMT
Additional note. The records I'm scrolling thru have fields across 3 tabs
that are all located on a parent tab. If I go between records while viewing
the first tab, the currency manager position changed event fires (still no
cbo.binding.format event). However, if I'm viewing tab 2 or 3 the cm
position changed event does NOT fire. Since I set all tab page
BindingContexts to equal the form BindingContext, I would think they are all
using the same cm. Auuugggghhh. Maybe I should just get a can of Raid and
see if that'll help! NJ
> BlankHi,
>
[quoted text clipped - 54 lines]
> = -1
> CType(CType(sender, Binding).Control, ComboBox).SelectedIndex
= -1
> End If
> Catch ex As Exception
[quoted text clipped - 5 lines]
> seems so standard but I just can't get past the problems. Would it be better
> to have a typed dataset by using the designer's dataset widget?
test - 29 Jul 2004 16:42 GMT
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.
> BlankHi,
>
[quoted text clipped - 54 lines]
> = -1
> CType(CType(sender, Binding).Control, ComboBox).SelectedIndex
= -1
> End If
> Catch ex As Exception
[quoted text clipped - 5 lines]
> seems so standard but I just can't get past the problems. Would it be better
> to have a typed dataset by using the designer's dataset widget?
Mike V. - 01 Aug 2004 18:32 GMT
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
[quoted text clipped - 79 lines]
>
>.
Malcolm - 27 Aug 2004 14:29 GMT
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
> Same problem here, and you don't see any books explaining
> how to handle nulls in comboboxes and which properties to
[quoted text clipped - 126 lines]
> >
> >.
albther - 16 Jun 2005 14:58 GMT
sbc installer get to a point and sats net work adapter no bound to tcp/ip i do what it says and still nothing could this be a virus because micro soft net . pass port sent me a email say sorry but this email has a virus conntact sender . sbc is not cheap when you cant uses your internet any body have this problem if email me to ill be out fixing my lawn sprinkler system to day thakyou ......