Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 10th, 2003, 08:42 AM
Registered User
 
Join Date: Jun 2003
Location: , MI, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Combo box DisplayMember only shows on 1st record

I am extremely new to Visual Basic, so this maybe a very basic question.

I have a form based on a SQL Server view (vwEvents). This form has two comboboxes also based on SQL Server views (luSite and luPart). The comboboxes (cboSite and Fuel) show the DisplayMember on the first record, but show the ValueMember on every record I move to. If I move back to the first record, it now only shows the ValueMember.

If you know of a better way of doing this, please post that also!

Thanks!

Here is the relevant code:


Code:
Imports System.Data
Imports System.Data.SqlClient
Public Class frmEvents
    Inherits System.Windows.Forms.Form

' Create connection to local SQL Server
    Dim EventsCon As SqlConnection = New SqlConnection("server=(local);database=RES;integrated security=TRUE;")

' Create SQLDataAdapters using SQL statements against views.
    Dim EventAdapt As SqlDataAdapter = New SqlDataAdapter("select * from vwEvents", EventsCon)

    Dim SiteAdapt As SqlDataAdapter = New SqlDataAdapter("SELECT SiteID, SiteName FROM luSite ORDER BY SiteName", EventsCon)

    Dim FuelAdapt As SqlDataAdapter = New SqlDataAdapter("SELECT PartID, PartName FROM luPart WHERE PartLocation = (SELECT PartTypeLocationID FROM vwPartTypeLocationRef WHERE PartTypeName = 'Fuel' AND PartTypeLocationName = 'N/A') ORDER BY PartName", EventsCon)

'Create datasets
    Dim EventDS As DataSet
    Dim SiteDS As DataSet
    Dim FuelDS As DataSet

'Create Dataviews
    Dim EventDV As DataView
    Dim SiteDV As DataView
    Dim FuelDV As DataView

'Create currency manager for form records
    Dim EventCM As CurrencyManager

'Fill Datasets
   Private Sub FillDataSetAndView()
        EventDS = New DataSet()
        SiteDS = New DataSet()
        FuelDS = New DataSet()

        Try
            SiteAdapt.Fill(SiteDS, "luSite")
            EventAdapt.Fill(EventDS, "vwevents")
            FuelAdapt.Fill(FuelDS, "luPart")
        Catch err As SqlException
            MessageBox.Show(err.Message)
        End Try

        EventDV = New DataView(EventDS.Tables("vwevents"))
        SiteDV = New DataView(SiteDS.Tables("luSite"))
        FuelDV = New DataView(FuelDS.Tables("luPart"))
        EventCM = CType(Me.BindingContext(EventDV), CurrencyManager)

    End Sub

' Bind Fields
    Private Sub BindFields()

'Clear all bindings
        EventName.DataBindings.Clear()
        DTEventStartDate.DataBindings.Clear()
        DTEventEndDate.DataBindings.Clear()
        cboSite.DataBindings.Clear()
        EventType.DataBindings.Clear()
        EventLength.DataBindings.Clear()
        Fuel.DataBindings.Clear()
        EventCode.DataBindings.Clear()
        EventNotes.DataBindings.Clear()

'Add data binding for cboSite combobox; declare value and display members
        cboSite.DataBindings.Add("Text", EventDV, "Site")
        Try
            cboSite.DataSource = SiteDS.Tables("luSite")
            cboSite.ValueMember = "SiteID"
            cboSite.DisplayMember = "SiteName"
        Catch err As Exception
            MessageBox.Show(err.Message + err.Source)
        End Try

' Add databindings for Fuel combobox; declare value and display members
        Fuel.DataBindings.Add("Text", EventDV, "Fuel")
        Try
            Fuel.ValueMember = "PartID"
            Fuel.DisplayMember = "PartName"
            Fuel.DataSource = FuelDS.Tables(0)
        Catch err As Exception
            MessageBox.Show(err.Message + err.Source)
        End Try

'Add rest of data bindings
        EventName.DataBindings.Add("Text", EventDV, "eventname")
        DTEventStartDate.DataBindings.Add("Text", EventDV, "EventStartDate")
        DTEventEndDate.DataBindings.Add("Text", EventDV, "EventStartDate")
        EventType.DataBindings.Add("Text", EventDV, "EventType")
        EventLength.DataBindings.Add("Text", EventDV, "EventLength")
        EventCode.DataBindings.Add("Text", EventDV, "EventCode")
        EventNotes.DataBindings.Add("Text", EventDV, "EventNotes")

End Sub

' On load call functions to fill data sets and bind fields
    Private Sub frmEvents_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDataSetAndView()
        BindFields()

    End Sub

'Move to first record
    Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        EventCM.Position = 0
    End Sub

'Move to previous record
    Private Sub btnMovePrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMovePrevious.Click
        EventCM.Position -= 1
    End Sub

'Move to next record
    Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveNext.Click
        EventCM.Position += 1
    End Sub

'Move to last record
    Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        EventCM.Position = EventCM.Count - 1
    End Sub
End Class
Reply With Quote
  #2 (permalink)  
Old June 13th, 2003, 09:51 AM
Registered User
 
Join Date: Jun 2003
Location: , MI, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Apparently

cboSite.DataBindings.Add("Text", EventDV, "Site")

needed to be

cboSite.DataBindings.Add("SelectedValue", EventDV, "Site")
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Combo Box posting to Wrong Record alaxmen Access 1 February 3rd, 2006 12:56 PM
how to browse a record through a combo box shankar Access VBA 3 December 22nd, 2004 08:49 PM
Find Record Use Combo Box martinaccess Access 2 October 17th, 2004 07:42 AM
Find Record Combo Box Wizard Won't Show 3rd Choice HenryE Access 0 February 2nd, 2004 11:52 PM



All times are GMT -4. The time now is 02:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.