Good evening!

I was hoping someone could help me here. I've been teaching myself C# for quite a while now, and I'm working on a project and have run into a problem.

I would like to use the binding navigator control to allow my users to browse through various tables, recordsets etc... the problem is C# wants me to set up a datasource to use that control...I can't really do this because I am allowing the user to decide on their own what data source they want to view. They could make a custom table outside of the program and then just point the program to the correct table by changing some settings in the program.

Is there a way to use the binding navigator control WITHOUT setting up a datasource using the wizard?

I would appreciate any input...I'm at a total loss here.

>Is there a way to use the binding navigator control WITHOUT setting up a datasource using the wizard?

Yes.

DataSet ds = new DataSet("TestDB");
        DataTable dt = new DataTable("Table1");
        BindingSource bind;
        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("No");
            dt.Columns.Add("Name");

            dt.Rows.Add("1", "A");
            dt.Rows.Add("2", "B");

            ds.Tables.Add(dt);

            bind = new BindingSource(ds, "Table1");
            textBox1.DataBindings.Add("Text", bind, "No");
            textBox2.DataBindings.Add("Text", bind, "Name");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bind.Position += 1;
        }

What about with specific SQL queries? Like: SELECT * FROM accounts WHERE id = [some variable];?

Can that be done?

>Can that be done?

Yes. Post your code please.

Not sure what code to post, I am working on creating a record editor, similar to an MS access form that navigates through a filtered set of records.

I don't have any code really on the record editor yet, it's a blank form. I wanted to figure out how I was going to let the users navigate before I got to into it and had a problem that needed to be fixed. Using the binding navigator would be the easier route, just wondered how I would get the binding navigator to update the fields. I'm used to using record sets and stuff in VBA, but that's not available here as far as I know, Otherwise I could simply use something like movenext or whatever and then update all of the text fields with the new data. The record set of course containing id numbers for fields in the tables...

I have some vba code that I would like to basically convert to C#, I can't figure out how to do it, so the closest I could find (I think) is a binding navigator.

I can post my VBA code if you want, or if that would help, but I somehow doubt it would?

Not sure what code to post, I am working on creating a record editor, similar to an MS access form that navigates through a filtered set of records.

I don't have any code really on the record editor yet, it's a blank form. I wanted to figure out how I was going to let the users navigate before I got to into it and had a problem that needed to be fixed. Using the binding navigator would be the easier route, just wondered how I would get the binding navigator to update the fields. I'm used to using record sets and stuff in VBA, but that's not available here as far as I know, Otherwise I could simply use something like movenext or whatever and then update all of the text fields with the new data. The record set of course containing id numbers for fields in the tables...

I have some vba code that I would like to basically convert to C#, I can't figure out how to do it, so the closest I could find (I think) is a binding navigator.

I can post my VBA code if you want, or if that would help, but I somehow doubt it would?

I think it would actually be really appreciated :)

I think it would actually be really appreciated :)

Sure...

The VBA code that is used on the account editor has nothing to do with navigating records though, but here is what source there is:

Option Compare Database

Private Sub cmdAddressCopy_Click()

'make sure the user isn't stupid

Dim intConfirm As Integer

intConfirm = MsgBox("Are you sure you wish to copy the physical address to the " & _
    "mailing address?" & vbCr & vbCr & "This cannot be undone.", vbYesNo, _
    "Confirm Address Copy")
   
If intConfirm = 7 Then
    GoTo lblStop
End If

Me.txtMailingAddress = Me.txtPhysicalAddress
Me.txtMailingCity = Me.txtPhysicalCity
Me.txtMailingState = Me.txtPhysicalState
Me.txtMailingZip = Me.txtPhysicalZip

lblStop:

End Sub

Private Sub cmdContractBuilder_Click()
    i = ContractBuilder(txtCompanyCode, Right(txtPrimaryLabAccount, 4), txtMRO, txtPrimaryLab)
End Sub

Private Sub cmdNavToggle_Click()

If cmdNavToggle = 0 Then
    DoCmd.MoveSize , , 11600, 15600
Else
    DoCmd.MoveSize , , 15840, 15600
End If

End Sub

'--------------------------------------------------------------
'Graham Thorpe 25-01-02
'
'Modified by Zachary Weber 10/23/2009
'--------------------------------------------------------------
Private Sub cmdSearch_Click()

'Update Completed for Ver. 2.1X on 08/11/09

    Dim strCompanyRef As String
    Dim strSearch As String
    
'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
        Me![txtSearch].SetFocus
    Exit Sub
End If
'---------------------------------------------------------------
        
'Performs the search using value entered into txtSearch
'and evaluates this against values in txtCompanyCode
        
    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("txtCompanyCode")
    DoCmd.FindRecord Me!txtSearch
        
    txtCompanyCode.SetFocus
    strCompanyRef = txtCompanyCode.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text
        
'If matching record found sets focus in txtSearch and shows msgbox
'and clears search control

    If strCompanyRef = strSearch Then
        MsgBox "Match Found For: " & strSearch, , "Find Company"
        txtSearch.SetFocus
        txtSearch = ""
        
    'If value not found sets focus back to txtSearch and shows msgbox
        Else
          MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
            , "Invalid Search Criterion!"
            txtSearch.SetFocus
    End If
End Sub

Private Sub Form_Load()

DoCmd.MoveSize , , 11600, 15600

End Sub

Not much help, the record navigation is done through embedded macros in Access. Attached is a picture of the editor as it is in access, that's what I want to replicate (different layout and fields, but same concept). The macros are all simple, there's a screen shot of one of them as well attached.

I would really appreciate your help this is a major hangup for me.

Edited 6 Years Ago by zachattack05: n/a

Attachments accounts.JPG 114.49 KB macro.JPG 19.38 KB

Maybe I'm just not sure what code exactly you want me to post?

Is there somewhere that shows an example of using a SQL SELECT statement with a binding navigator?

This article has been dead for over six months. Start a new discussion instead.