Results 1 to 11 of 11

Thread: How to remove Duplicate Combobox & Load the value into Text box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    How to remove Duplicate Combobox & Load the value into Text box

    Dear all,

    I have database like this

    Manufacture Model No Length Width height

    Manufacture 1 MD-01 200 300 100

    Manufacture 1 MD-02 300 400 100

    Manufacture 1 MD-03 400 300 150

    Manufacture 2 MAD-01 200 450 100

    Manufacture 2 MAD-02 250 400 100

    Manufacture 3 MDI-01 300 300 100

    Manufacture 4 MOv-01 350 300 100

    I would like to create 2 combobox -

    1) Manufacture 2 ) model No

    Manufacture should display for above example Manufacture 1,Manufacture 2,Manufacture 3, Manufacture 4

    when particular manufacture selected for example Manufacture 2 -> combox should display only MAD-01 & MAD 02.

    Based on both selection text box must me loaded with length, width , height.

    i tried sample code & try to assign the combox with database value. I found duplicate list of column. Like for combobox1 accumulate

    Manufacture 1

    Manufacture 1

    Manufacture 1

    Manufacture 2

    Manufacture 2

    Manufacture 3

    Manufacture 4


    Please share some example program

  2. #2
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Re: How to remove Duplicate Combobox & Load the value into Text box

    In which programming language? VB6, VB.NET, C#...?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Re: How to remove Duplicate Combobox & Load the value into Text box

    I am using visual basic ultimate 2013 for desktop version. Please share atleast example program to conduct it.Solar_Panel.pdf

    I have attached pdf file of my ms- access database here,

    I have created 2 combo box , Based on section of combobox box length, width. height should be loaded into text boxName:  Image_database.jpg
Views: 2294
Size:  20.8 KB

    for combobox1 , manufacture duplicate should be removed & show only Manufacture name

    in combox 2 , manufacture model no should be shown.

    Its nothing but Using filter option In excel.

    I have created comobox-> use databounding items->

    selected datasource, datamember,value member,selected value
    Last edited by AJITnayak; Sep 11th, 2015 at 06:41 AM.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Re: How to remove Duplicate Combobox & Load the value into Text box

    Visual Studio is a wide term. Is that VB.NET or C#? You should've posted this request in appropriate section, not here. I've reported your thread to be moved in one of these sections when you say what language are you using.

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: How to remove Duplicate Combobox & Load the value into Text box

    I'm going to take a wild guess and assume you're using VB.Net so I'm moving your thread there. If that's wrong and you're using e.g. C# then hit the report button and ask us to move it again.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Re: How to remove Duplicate Combobox & Load the value into Text box

    I am using Vb.net here.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to remove Duplicate Combobox & Load the value into Text box

    This uses a List(of Class) and several LINQ methods - Select, Distinct, Where, First, and ToArray to query the list based on user selection:

    Code:
    Public Class Form1
    
        Dim items As New List(Of item)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            items.Add(New item With {.manufacturer = "Manufacture 1", .model = "MD-01", .length = 200, .width = 300, .height = 100})
            items.Add(New item With {.manufacturer = "Manufacture 1", .model = "MD-02", .length = 300, .width = 400, .height = 100})
            items.Add(New item With {.manufacturer = "Manufacture 1", .model = "MD-03", .length = 400, .width = 300, .height = 150})
            items.Add(New item With {.manufacturer = "Manufacture 2", .model = "MAD-01", .length = 200, .width = 450, .height = 100})
            items.Add(New item With {.manufacturer = "Manufacture 2", .model = "MAD-02", .length = 250, .width = 400, .height = 100})
            items.Add(New item With {.manufacturer = "Manufacture 3", .model = "MDI-01", .length = 300, .width = 300, .height = 100})
            items.Add(New item With {.manufacturer = "Manufacture 4", .model = "MOv-01", .length = 350, .width = 300, .height = 100})
    
            ComboBox1.Items.AddRange(items.Select(Function(i) i.manufacturer).Distinct.ToArray)
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            If ComboBox1.SelectedIndex = -1 Then Return
            ComboBox2.Items.Clear()
            ComboBox2.Items.AddRange(items.Where(Function(i) i.manufacturer = ComboBox1.Text).Select(Function(i) i.model).ToArray)
        End Sub
    
        Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
            If ComboBox2.SelectedIndex = -1 Then Return
            Dim i As item = items.First(Function(itm) itm.model = ComboBox2.Text)
            TextBox1.Text = String.Format("Length: {0}{3}Width: {1}{3}Height: {2}", i.length, i.width, i.height, Environment.NewLine)
        End Sub
    End Class
    
    Public Class item
        Public manufacturer As String
        Public model As String
        Public length As Integer
        Public width As Integer
        Public height As Integer
    End Class

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to remove Duplicate Combobox & Load the value into Text box

    I just noticed your combobox is databound... The exact way to achieve what you're looking for depends on how you bound the comboboxes

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to remove Duplicate Combobox & Load the value into Text box

    Here's an alternative using a db as your datasource, This uses databinding:

    Code:
    Imports System.Data.OleDb
    Imports System.Data.SqlClient
    
    Public Class Form1
    
        Dim dt As New DataTable
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'Access@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
            Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;Persist Security Info=False;")
            Dim da As New OleDbDataAdapter("SELECT * FROM tableName", conn)
            da.Fill(dt)
            '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
            'Sql Server@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
            'Dim conn As New SqlConnection("Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\MyFolder\MyData.mdf;")
            'Dim da As New SqlDataAdapter("SELECT * FROM tableName", conn)
            'da.Fill(dt)
            '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
            ComboBox1.DisplayMember = "manufacturer"
            ComboBox1.DataSource = dt.DefaultView.ToTable(True, "manufacturer")
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            If ComboBox1.SelectedIndex = -1 Then Return
            Dim dv As New DataView(dt, "manufacturer = '" & ComboBox1.Text & "'", "", DataViewRowState.CurrentRows)
            ComboBox2.DisplayMember = "model"
            ComboBox2.DataSource = dv
            TextBox1.DataBindings.Clear()
            TextBox1.DataBindings.Add("Text", dv, "length")
            TextBox2.DataBindings.Clear()
            TextBox2.DataBindings.Add("Text", dv, "width")
            TextBox3.DataBindings.Clear()
            TextBox3.DataBindings.Add("Text", dv, "height")
        End Sub
    
    End Class

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Re: How to remove Duplicate Combobox & Load the value into Text box

    @ paul i have used your code. Its exact how i wanted. I am facing problem in displaying model no.Name:  combo1.jpg
Views: 2071
Size:  19.1 KB

    where my database look like this

    Code:
    Imports System.Data.OleDb
    Imports System.Data.SqlClient
    
    Public Class Form1
    
        Dim dt As New DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\AccessDatabase\Manufacture.accdb;Persist Security Info=False;")
            Dim da As New OleDbDataAdapter("SELECT * FROM Solar_Panel", conn)
            da.Fill(dt)
    
            ComboBox1.DisplayMember = "manufacturer"
            ComboBox1.DataSource = dt.DefaultView.ToTable(True, "manufacturer")
    
    
        End Sub
    
    
    
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
            If ComboBox1.SelectedIndex = -1 Then Return
            Dim dv As New DataView(dt, "manufacturer = '" & ComboBox1.Text & "'", "", DataViewRowState.CurrentRows)
            ComboBox2.DisplayMember = "model"
            ComboBox2.DataSource = dv
            TextBox1.DataBindings.Clear()
            TextBox1.DataBindings.Add("Text", dv, "length")
            TextBox2.DataBindings.Clear()
            TextBox2.DataBindings.Add("Text", dv, "width")
            TextBox3.DataBindings.Clear()
            TextBox3.DataBindings.Add("Text", dv, "Height")
        End Sub
    
    
    End Class
    Name:  database image .jpg
Views: 2022
Size:  17.7 KB

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to remove Duplicate Combobox & Load the value into Text box

    Your db field name is "model no" instead of "model"
    I'm not sure, but there might be further issues using a 2 word field name. The simplest fix is to change the field name in the db

Tags for this Thread

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