Results 1 to 10 of 10

Thread: VB6 Unicode-capable ADO-DataBinding-Control

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    VB6 Unicode-capable ADO-DataBinding-Control

    Not sure, whether some of you have run into this, but the MS-ADODC-Control does not support Unicode when linked to Control-Bindings.

    So the 3 Binding-Controls in this Demo can be seen as an Unicode-aware Replacement:
    - not only for the ADODC-Control (represented by ucBindingNav)
    - but also for a Scrollable-DetailView-Container (which hosts Bound-Control-entries "PropertyGrid-like")

    Perhaps a ScreenShot explains better, what the Main-Control (ucBindingCont) does:


    In this example, the ucBindingCont(ainer) fills the Form in its entirety,
    and is the only Control one has to create on the given Form.

    The ADODC-like Navigation-Bar at the Bottom of the Screenshot (ucBindingNav) is internally part of that ucBindingCont.ctl.

    The approach needs a Unicode-library (for the Controls which are bound to ADO-Rs later),
    and it should work with any decent Unicode-Control-lib, like e.g. the OCXes which are available from:
    - CyberActiveX
    - CodeJock
    - or Krools OCX-version
    Note, that neither Control-Lib has to offer special DataSource/DataField Props on their Controls -
    the Binding-implementation here will not require these (they will be ignored, even if they do exist).

    In this Demo I was making use of Krools latest OCX-Version (VBCCR17), which is therefore a prerequisite -
    (which one has to download and register, before running this Demo-Project makes any sense).

    Note, that the Conrols of the Unicode-lib one wants to use - are instantiated (and later accessed) in a LateBound fashion,
    for that to work - only their ProgIDs have to be defined (for each of the Control-Types which make sense) - here's the ones for Krools lib:
    Code:
    Const TxtCtlProgID = "VBCCR17.TextBoxW"
    Const CmbCtlProgID = "VBCCR17.ComboBoxW"
    Const DatCtlProgID = "VBCCR17.DTPicker"
    Const ChkCtlProgID = "VBCCR17.CheckBoxW"
    With these Constants in place, the Definition which creates the Binding-View (as seen in the ScreenShot) is this:
    Code:
    Private Sub CreateBoundControlsView(RsUnicode As ADODB.Recordset, RsLanguages As ADODB.Recordset)
      With ucBindingCont1 'the dynamic adding + binding of Controls (all LateBound, using the above ProgID-Consts)
        .Visible = False  'we hide the Binding-Container here, to avoid Flickering during Control-(Re-)Adds
          .SetTitle "ADO.Rs-Binding to UniCode-Controls"
              
              .AddBoundCtlFor "Welcome", TxtCtlProgID, "Change", "Text", "a longer Unicode-Welcome-ToolTip with chinese Chars: " & ChrW(&H6B22) & ChrW(&H8FCE)
              .AddBoundCtlFor "Country", TxtCtlProgID, "Change", "Text", "ToolTip for the Country-Field"
              .AddBoundCtlFor "Capital", TxtCtlProgID, "Change", "Text", "ToolTip for the Capital-Field"
              .AddBoundCtlFor "Checked", ChkCtlProgID, "Click", "Value", "ToolTip for the Checked-Field"
              .AddBoundCtlFor "SomeDate", DatCtlProgID, "Change", "Value"
              .AddBoundCtlFor "Language", CmbCtlProgID, "Click", RsLanguages  '<- instead of a ValuePropName, we pass an FK-Rs to our ComboCtl
          
          Set .DataSource = RsUnicode 'finally we set the DataSource to our Main-Rs, to bring the Bindings to life
        .Visible = True  'reset the hidden-state of the Container
      End With
    End Sub
    The magenta-colored Comment above describes, what is needed for an automatic "ForeignKey-Combo-DropDown-Binding".
    So, a Binding-Def-CodeLine requires the following Parameters:
    - the Rs-FieldName in the first Parameter (when no explicit Caption is set, these FieldNames will provide also the Labeling in the View)
    - the ProgID (for Control-Creation... above marked in blue, as defined in our Consts)
    - the Name of the Control-Event, which tells us about a Value-change in the Control (often "Change", but sometimes "Click" or whatever)
    - the Name of the Value-Property of the Control, we will bind the Rs-Value to later on
    - and finally an optional ToolTip-Text, followed by an optional FormatString argument

    That's it (basically) to create a nice looking Data-Entry-Form (or -View)...
    For full CRUD-operation-support (Create, Read, Update Delete) via the Bottom-NavBar, only one EventHandler has to be implemented:
    Code:
    Private Sub ucBindingCont1_NavButtonClick(ByVal BtnType As eNavButtonType, CancelClickEvent As Boolean)
      On Error Resume Next
      With ucBindingCont1.DataSource  'we just call the matching Methods of our DataSource (of type ADODB.Recordset)
        Select Case BtnType           'in a real App one might want to throw some MessageBoxes like "Do you really want to save" at the User
          Case navBtnRequery: .Requery
          Case navBtnDelete:  .Delete
          Case navBtnAddNew:  .AddNew
          Case navBtnSave:    .UpdateBatch
        End Select
      End With
      If Err Then MsgBox Err.Description: Err.Clear
    End Sub
    For usage in your own Projects, only the 3 UserControls (ucBindingCont, ucBindingNav and ucBindingEntry)
    have to be included (directly as Private UserControls - they are small enough - and use no SubClassing or some such).
    Other than the ADO-reference (which is obvious when we use ADO-Bindings) no other dependency is needed.

    Well, I hope the above explanations were clear enough to get you started, here is the Demo-Zip:
    BindingDemo.zip

    Have fun,

    Olaf

  2. #2
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    why i cant see data or combo box shown in ur top image and whats this error means ?

    when i click for example on country label or .. i see this error :

    Code:
    Private Sub UserControl_Click()
      mCtlEx.SetFocus
    End Sub

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    Quote Originally Posted by Black_Storm View Post
    why i cant see data or combo box shown in ur top image and whats this error means ?

    when i click for example on country label or .. i see this error :

    Code:
    Private Sub UserControl_Click()
      mCtlEx.SetFocus
    End Sub
    "ObjectVariable not set"
    mCtlEx is of type vbControlExtender (holding a reference to the LateBound - via Controls.Add - generated Control).

    Apparently the LateBound-Control-instancing (from the "lib of Unicode-Controls") did fail in a prior step.

    So, did you download and install Krools Unicode-ActiveX-Lib in version 1.7, then registering this OCX?

    The CodeBank-article, from where you can download it, is here:
    https://www.vbforums.com/showthread....on-controls%29

    The OCX-FIle is sitting in this *.rar Archive (just remove the zip-ending): VBCCR17.OCX.rar.zip

    Olaf

  4. #4
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    how can use this sample for my problem in this thread : ? i want just design a control like as data combo with bidnig fata and row source, row field and can themed i dont want use another ocx In my control for use it

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    Quote Originally Posted by Black_Storm View Post
    how can use this sample for my problem in this thread : ? i want just design a control like as data combo with bidnig fata and row source, row field and can themed i dont want use another ocx In my control for use it
    The "RowSource-Handling" of the DataBound Combo is sitting in ucBindingEntry.ctl of this project.
    (you could have found this out yourself, by stepping through the code via <F8> for example).

    I also don't know, where the big problem is, in making a normal Combo understanding "RowSources".

    Here is a little Snippet for a simple "RowSource-supporting"-Combo-Ctl, named ucFKCombo - which only needs a normal Combo1 placed within it:
    Code:
    Option Explicit
    
    Event Click()
    Private mFKArr()
    
    Private Sub Combo1_Click()
      RaiseEvent Click
    End Sub
    Private Sub UserControl_Initialize()
      ReDim mFKArr(-1 To -1, -1 To -1)
    End Sub
    Private Sub UserControl_Resize()
      Combo1.Width = ScaleWidth
    End Sub
    
    Public Property Set RowSource(ByVal RHS As Object)
      On Error Resume Next
        ReDim mFKArr(-1 To -1, -1 To -1)
        Dim i As Long, vID: vID = Value '<- buffer the prior FK-ID
        mFKArr = RHS.Clone.GetRows
        Combo1.Clear
          For i = 0 To UBound(mFKArr, 2): Combo1.AddItem mFKArr(1, i): Next
        Combo1.ListIndex = FindFKIndexFor(vID) 'try to find the prior FK-ID
      If Err Then Err.Clear
    End Property
    
    Public Property Get Value()
      Value = Null
      If UBound(mFKArr, 2) > -1 Then
        If Combo1.ListIndex >= 0 Then Value = mFKArr(0, Combo1.ListIndex)
      End If
    End Property
    Public Property Let Value(RHS)
      If UBound(mFKArr, 2) > -1 Then Combo1.ListIndex = FindFKIndexFor(RHS)
    End Property
    
    Private Function FindFKIndexFor(vID) As Long
      Dim i As Long
      For i = UBound(mFKArr, 2) To 0 Step -1
        If mFKArr(0, i) = vID Then Exit For
      Next
      FindFKIndexFor = i
    End Function
    Demo-Code for a Form (which then should contain ucFKCombo1)
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Dim Rs
      Set Rs = CreateObject("ADODB.Recordset")
          Rs.Fields.Append "ID", vbInteger
          Rs.Fields.Append "Name", vbString
          Rs.Open
          Rs.AddNew Array(0, 1), Array(1, "Name1")
          Rs.AddNew Array(0, 1), Array(2, "Name2")
          Rs.AddNew Array(0, 1), Array(3, "Name3")
      
      Set ucFKCombo1.RowSource = Rs
          ucFKCombo1.Value = 3
    End Sub
    
    Private Sub ucFKCombo1_Click()
      Caption = ucFKCombo1.Value
    End Sub
    HTH

    Olaf

  6. #6
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    575

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    i explained in my posted thread create-a-activex-used-combox-and-move-all-methods-and-properties-to-this-new-control
    i am not looking for row source or row filed only i am looking for any data combo box like as normal combo box with all properties and events and methods in data combo box but i want can support theme too,i want use manefest file or i want use skinners to can change theme of datacombo box,my problem is about set theme on data combo box,if i cant find any way so i should be try for find any user control like as data combo box but fixed theme problem

  7. #7
    Hyperactive Member
    Join Date
    May 2018
    Location
    Russia
    Posts
    315

    Question Re: VB6 Unicode-capable ADO-DataBinding-Control

    Quote Originally Posted by Schmidt View Post
    Not sure, whether some of you have run into this, but the MS-ADODC-Control does not support Unicode...
    What do you mean? This is VSFlexGrid + ADODC Control:
    Name:  ADODC.png
Views: 109
Size:  4.0 KB

    Intrinsic Data control doesn't support Unicode. But not the ADODC.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    Quote Originally Posted by Nouyana View Post
    What do you mean?

    Intrinsic Data control doesn't support Unicode. But not the ADODC.
    The MS-ADODC in conjunction with Krools Unicode-Textbox for example,
    does not support Unicode...

    Hence this CodeBank-entry, which shows an alternative way to bind Krools Controls
    (via an ADODC-alternative).

    Olaf

  9. #9
    Hyperactive Member
    Join Date
    May 2018
    Location
    Russia
    Posts
    315

    Arrow Re: VB6 Unicode-capable ADO-DataBinding-Control

    Quote Originally Posted by Schmidt View Post
    The MS-ADODC in conjunction with Krools Unicode-Textbox for example,
    does not support Unicode
    Name:  ADODC_Krool.png
Views: 82
Size:  3.4 KB

  10. #10
    Hyperactive Member
    Join Date
    May 2018
    Location
    Russia
    Posts
    315

    Re: VB6 Unicode-capable ADO-DataBinding-Control

    Anyway, there is no dependencies except msado25.tlb
    And it's very beautiful as for me. Thank you for it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width