c1DbNavigator with C1TrueDbGrid

Posted by: morourke on 26 February 2018, 5:08 am EST

    • Post Options:
    • Link

    Posted 26 February 2018, 5:08 am EST

    Hi I am trying to implement two features with the c1TrueDBGrid. I want to retain the formatting (column widths) of the grid and I also want to show the record number in the C1DbNavigator1. In the first instance the data loads fine and the Navigator shows the correct number of records while also showing the correct information. Clicking on a row in the grid will display the corresponding number in the Navigator and clicking on the navigator will move the highlight in the grid to the correct row.

    However, the grid loses its formatting.

     In the second scenario, the grid retains its layout but the Navigator does nothing other than display that there is one record and that the row is positioned at record 1.
    

    I know I must be missing something simple, but I have spent hours going around in circles on this. So any information on where I am going wrong will be appreciated.

    'The common code for loading the data is s…

    Dim sql As String = "select top 50 br_cd as brncode,br_name as bname from branches "

    Dim da As SqlDataAdapter = New SqlDataAdapter(sql, strSQLConnectionString)

    Dim ds As DataSet = New DataSet

    da.Fill(ds, “myTable”)

    'Common Code Ends…

    (1)

    Navigator works but holdfields does not

    C1TrueDBGrid1.DataSource = ds.Tables(0)

    C1DbNavigator1.DataSource = C1TrueDBGrid1.DataSource

    (2) However holdfields works but navigator does not

     C1TrueDBGrid1.SetDataBinding(ds, "myTable", True)
        C1DbNavigator1.DataSource = C1TrueDBGrid1.DataSource
    End Sub
    
    Thanks in advance
    Morke
    
  • Posted 26 February 2018, 6:34 pm EST

    Hi Morke!

    This issue is in discussion with the team internally. We will inform you once it is resolved.

    Best regards,

    Meenakshi

  • Posted 27 February 2018, 7:55 pm EST

    Hi,

    Thanks a lot.

    Regards

    Morke

  • Posted 12 March 2018, 2:17 am EST

    Hi Meenakshi,

    Has anyone come up with a solution for the above?

    Regards

    Morke

  • Posted 12 March 2018, 2:18 pm EST

    Hi Morke!

    The solution is to use BindingSource component in this case. I am attaching the modified sample for your reference. Kindly check.

    Prj_TDBWithC1DbNavigator_Fixed.zip

    Best regards,

    Meenakshi

  • Posted 16 March 2018, 8:34 pm EST

    Hi,

    Thanks for that, worked great.

    I am enclosing the code I am using as it may assist someone else seeking to bind to both the grid and the navigator. Amend or remove as you see fit.

    Regards

    Morke

    '*************************************************************************************

    ’ Populates C1TrueDBGrid via query while maintaining design time layout of grid.

    ’ Also optionally links grid to c1DbNavigator

    ’ Designer was used to add two columns: brncode, bname

    ’ ************************************************************************************

    Imports System.Data.OleDb

    Public Class frmTestGCAnswer

    Private myOLEDBConnectionString As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source=C:\myTestFolder\memship.mdb; Jet OLEDB:Database Password =window; "

    Private Sub frmTestGrapeCityAnswer_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    LoadMyGrid(gridBranches, "SELECT * FROM branches order by bname ", MyC1DbNavigator1)

    End Sub

    ’ *****************************************************************************

    ’ Below can be added to a module and thereafter may be called from any form

    ’ LoadMyGrid(gridBranches, “SELECT * FROM branches”, C1DbNavigator)

    ’ Returns: False if error detected

    ’ *****************************************************************************

    Public Function LoadMyGrid(MyC1Grid As C1.Win.C1TrueDBGrid.C1TrueDBGrid, strSql As String, Optional MyC1Navigator As C1.Win.C1Input.C1DbNavigator = Nothing) As Boolean

    Dim ds As New DataSet

    Dim bs As New BindingSource

    Dim conn As New OleDb.OleDbConnection

    Dim Command As New OleDb.OleDbCommand

    Dim adapter As New OleDbDataAdapter

    Dim lAllOkay As Boolean = False 'if no error then set to true below

    Try

    conn = New OleDbConnection(mstrOLEDBConnectionString)

    conn.Open()

    Command = New OleDbCommand(strSql, conn)

    adapter.SelectCommand = Command

    adapter.Fill(ds, “MyTable”)

    adapter.Dispose()

    Command.Dispose()

    conn.Close()

    bs.DataSource = ds

    bs.DataMember = ds.Tables(0).TableName

    MyC1Grid.SetDataBinding(bs, “”, True)

    'If a C1DbNavigator is passed in then also bind it

    If Not IsNothing(MyC1Navigator) Then

    MyC1Navigator.DataSource = bs

    End If

    lAllOkay = True

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    LoadMyGrid = lAllOkay

    End Function

    End Class

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels