Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 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 Display Modes
  #1 (permalink)  
Old June 18th, 2008, 12:30 AM
Registered User
 
Join Date: Jun 2008
Location: Kuala Lumpur, Selangor, Malaysia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Gini
Default Combo box to display items from parent combo box

When I select an item from the first combo box, the second combo box should be populated with items related to the first combo box selection. I am developing a system with a database, and the datasource is 'dsInventory'. This is where all the information to be displayed is retrieved. And there are binding sources to bind the datasource items to the combo boxes.

My question is how do I make the second combo box display ONLY sub values of each value of the first combo box.

But now the problem that I face is that all the items from the first combo box display the same sub items in the second combo box when it is selected. Ex :


First Combo Box selections :

COUVETURE
CREAM
DOUGH
BISCUITS
PM
CC , etc

Second Combo box :

If 'PM' from the first combo box is selected, then the items that should display are :

B
C
L
P
W

Now...I choose any item from the first combo box. The same list of items of the second combo box (B,C,L,P,W) display for all the items from the first combo box.

The idea is to just display the items related to the 1st combo box.

The software I have used in VB.net 2008 and Sql Server 2000.

Below is the coding for the section I want working. The bold section of the code is where the data source is linked to the table adapters.

Code:
Imports System.Windows.Forms.DataGrid
Imports System.Data.SqlClient

Public Class InventoryMainForm
    Private CatCodeDesc As String
    Private CatCode As String
    Private WarehouseLocation As String
    Private Warehouse As String
    Private UOMCode As String
    Private subcatcode As String
    Private subcat1code As String
    Private subcat2code As String
    Private subcat3code As String
    Private AddNew As Boolean
    Dim DQcheck As New SqlCommand
    Dim DHcheck As New SqlDataAdapter
    Dim DScheck As New DataSet
    Dim Dvcheck As New DataView

Private Sub InventoryMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Me.CountryTableAdapter.Fill(Me.DsSales.country)
            Me.Inv_itemsubcategoryTableAdapter.Fill(Me.dsInventory.inv_itemsubcategory)
            Me.Inv_itemlocTableAdapter.Fill(Me.dsInventory.inv_itemloc)
            Me.Inv_itemuomTableAdapter.Fill(Me.dsInventory.inv_itemuom)
            Me.Inv_itemcategoryTableAdapter.Fill(Me.dsInventory.inv_itemcategory)
            Me.Inv_itemCat3TableAdapter.Fill(Me.dsInventory.inv_itemCat3)
            Me.Inv_itemCat4TableAdapter.Fill(Me.dsInventory.inv_itemCat4)
            Me.Inv_itemCat5TableAdapter.Fill(Me.dsInventory.inv_itemCat5)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text + " FrmLoad", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

 '=========Inventory Item Sub Category===========
    Private Sub subcatBindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subcatBindingNavigatorAddNewItem.Click
        subcatcode = cmbsubcatcode.SelectedValue
        cmbsubcatcode.Visible = False
        txtsubcat.Visible = True
        cmbitemcat.Text = ""
        txtsubcat.Text = ""
        txtsubcatdesc.Text = ""
        subcat(False)
        AddNew = True
        cmbitemcat.Focus()
    End Sub

    Private Sub subcat(ByVal check As Boolean)

        dgsubcategory.Enabled = check
        BindingNavigatorMoveFirstItem1.Enabled = check
        BindingNavigatorMoveLastItem1.Enabled = check
        BindingNavigatorMoveNextItem1.Enabled = check
        BindingNavigatorMovePreviousItem1.Enabled = check
        BindingNavigatorCountItem1.Enabled = check
        BindingNavigatorPositionItem1.Enabled = check

        subcatBindingNavigatorRefre****em.Visible = check
        subcatBindingNavigatorAddNewItem.Visible = check
        subcatBindingNavigatorEditItem.Visible = check
        cmbsubcatcode.Visible = check
        txtitemcat.Visible = check
        If check = False Then
            check = True
            subcatBindingNavigatorDeleteItem.Text = "Cancel"
        Else
            check = False
            subcatBindingNavigatorDeleteItem.Text = "Delete"
        End If

        subcatBindingNavigatorSaveItem.Visible = check
        txtsubcat.Visible = check
        cmbitemcat.Visible = check
        txtsubcatdesc.Enabled = check
    End Sub

    Private Sub subcatBindingNavigatorEditItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subcatBindingNavigatorEditItem.Click
        If dgsubcategory.RowCount > 0 Then
            subcatcode = cmbsubcatcode.SelectedValue
            subcat(False)
            txtsubcat.Enabled = False
            cmbitemcat.Enabled = False
            cmbitemcat.Focus()
        Else
            MessageBox.Show("No record to edit.", Me.Text + " - Item Category Level 2", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub subcatBindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subcatBindingNavigatorDeleteItem.Click
        Try
            If dgsubcategory.RowCount > 0 Then
                If subcatBindingNavigatorDeleteItem.Text = "Delete" Then
                    If MessageBox.Show("Are you sure to delete this record?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
                        gSQLstr = "SELECT COUNT(iim_subcat) FROM inv_itemmaster WHERE  iim_subcat = " & cSQL(cmbsubcatcode.Text) & ""
                        If gSQLcon.State = ConnectionState.Closed Then
                            gSQLcon.Open()
                        End If
                        DQcheck.Connection = gSQLcon
                        DQcheck.CommandText = gSQLstr
                        DHcheck.SelectCommand = DQcheck
                        DHcheck.Fill(DScheck, ("subcat_list"))
                        Dvcheck.Table = DScheck.Tables("subcat_list")
                        If Dvcheck.Table.Rows(0).Item(0) > 0 Then
                            MessageBox.Show("Record cannot be deleted!", Me.Text + " - Item Category Level 2", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Else
                            InvitemsubcategoryBindingSource.RemoveCurrent()
                            Inv_itemsubcategoryTableAdapter.Update(dsInventory)
                            MessageBox.Show("Record has been deleted.", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        End If
                        DScheck.Clear()
                        gSQLcon.Close()
                    End If
                Else
                    If AddNew = True Then
                        AddNew = False
                    End If
                    subcat(True)
                    txtsubcatdesc.Enabled = False
                    refreshsubcat()
                    cmbsubcatcode.SelectedValue = subcatcode

                End If
            Else
                MessageBox.Show("No record to delete.", Me.Text + " - Item Category Level 2", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text + " - Item Category Level 2(Delete)", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub subcatBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subcatBindingNavigatorSaveItem.Click
        Dim strmsg As String = ""
        Try
            If MessageBox.Show("Save Item?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
                If AddNew = True Then
                    If txtsubcat.Text.Trim = "" Then
                        strmsg = strmsg & "Required field - Category Code." & vbCrLf
                    Else
                        gSQLstr = "SELECT COUNT(iis_code) FROM inv_itemsubcategory WHERE  iis_code = " & cSQL(txtsubcat.Text) & ""
                        If gSQLcon.State = ConnectionState.Closed Then
                            gSQLcon.Open()
                        End If
                        DQcheck.Connection = gSQLcon
                        DQcheck.CommandText = gSQLstr
                        DHcheck.SelectCommand = DQcheck
                        DHcheck.Fill(DScheck, ("subcat_list"))
                        Dvcheck.Table = DScheck.Tables("subcat_list")


                        If Dvcheck.Table.Rows(0).Item(0) > 0 Then
                            strmsg = strmsg & "Required field - Category Code already exits, please assign another Category Code!" & vbCrLf
                        End If
                        DScheck.Clear()
                        gSQLcon.Close()
                    End If
                End If
                If cmbitemcat.Text.Trim = "" Then
                    strmsg = strmsg & "Required field - Level 1 Category." & vbCrLf
                End If
                If txtsubcatdesc.Text.Trim = "" Then
                    strmsg = strmsg & "Required field - Description." & vbCrLf
                End If
                If strmsg = "" Then
                    If AddNew = True Then
                        dsInventory.inv_itemsubcategory.Addinv_itemsubcategoryRow(Trim(txtsubcat.Text), txtsubcatdesc.Text, cmbitemcat.Text)
                        Inv_itemsubcategoryTableAdapter.Update(dsInventory.inv_itemsubcategory)
                        Inv_itemsubcategoryTableAdapter.Fill(dsInventory.inv_itemsubcategory)
                        AddNew = False
                    Else
                        InvitemsubcategoryBindingSource.EndEdit()
                        Inv_itemsubcategoryTableAdapter.Update(dsInventory.inv_itemsubcategory)
                    End If
                    MessageBox.Show("Record saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.None)
                    subcat(True)
                    cmbsubcatcode.Enabled = True
                    cmbsubcatcode.SelectedValue = subcatcode
                Else
                    MessageBox.Show(strmsg, Me.Text + " -Item Category Level 2", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If
        Catch ex As Exception
            If ex.Message.Contains("Column 'iis_code, iis_itemcode' is constrained to be unique. ") = True Then
                MessageBox.Show("The code already exits, please assign another code!", Me.Text + " - Item Category Level 2", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            Else
                MessageBox.Show(ex.Message, Me.Text + " - Item Category Level 2(Save)", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End Try
    End Sub

    Private Sub subcatBindingNavigatorRefre****em_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles subcatBindingNavigatorRefre****em.Click
        refreshsubcat()
    End Sub

    Private Sub refreshsubcat()
        Try
            Inv_itemsubcategoryTableAdapter.Fill(dsInventory.inv_itemsubcategory)
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text + " - Item Category Level 2(Refresh)", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
        Me.Close()
    End Sub


Please help me solve this problem.

Thanks.
Reply With Quote
Reply


Thread Tools
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
put mailto: links on list items in a combo box? webwolf Flash (all versions) 0 September 12th, 2008 08:01 AM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Combo box items not displaying djam C# 3 March 22nd, 2005 03:13 AM
Combo box with different display and send values iniro VB.NET 2002/2003 Basics 3 November 9th, 2004 11:34 AM



All times are GMT -4. The time now is 10:17 AM.


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