-
Sep 11th, 2015, 02:18 AM
#1
Thread Starter
Junior Member
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
-
Sep 11th, 2015, 06:17 AM
#2
Hyperactive Member
Re: How to remove Duplicate Combobox & Load the value into Text box
In which programming language? VB6, VB.NET, C#...?
-
Sep 11th, 2015, 06:20 AM
#3
Thread Starter
Junior Member
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 box
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.
-
Sep 11th, 2015, 07:14 AM
#4
Hyperactive Member
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.
-
Sep 11th, 2015, 09:13 AM
#5
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
-
Sep 13th, 2015, 10:49 PM
#6
Thread Starter
Junior Member
Re: How to remove Duplicate Combobox & Load the value into Text box
-
Sep 14th, 2015, 06:14 PM
#7
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 14th, 2015, 06:18 PM
#8
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 15th, 2015, 09:04 PM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 15th, 2015, 11:58 PM
#10
Thread Starter
Junior Member
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.
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
-
Sep 16th, 2015, 12:05 AM
#11
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|