• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Query needed vb 2005

Hello experts.I have a problem  with a form.I need a query when i choose a suplier from a combobox to show only the products that belong to this supplier only.

I select asuplier from a combobox and the product choose is in  another combobox.

So if i choose suplier x in the combobox i must only able to choose the products from the other combobox  that belong to the spicify supplier .

I am  using vb 2005 linked from  ms access 2003 and i am using binding navigator

Thnks expects i  want a example and a tutorial about queris general.

Regards demoniumz
0
demoniumz
Asked:
demoniumz
  • 54
  • 27
  • 5
1 Solution
 
josephwalshCommented:
Sample Code PRovided ebelow :

Private Sub cboProductID_GotFocus()
On Error GoTo Error_cboProductID_GotFocus

    Dim strsql As String

    With Me
        If IsNull(!cboSupplierID) Or !cboSupplierID = "" Then
            MsgBox "You must supply a SupplierID before a ProductID."
            !cboSupplierID.SetFocus
            Exit Sub
        End If
        strsql = "SELECT * FROM tblProducts WHERE strSupplierID = '" & !cboSupplierID & "'"
        strsql = strsql & " ORDER by intProductID"
        !cboProductID.RowSource = strsql
        !cboProductID.Requery
        '!cboProductID.Dropdown
    End With

Exit_cboProductID_GotFocus:
    Exit Sub
   
Error_cboProductID_GotFocus:
    MsgBox "Error No : " & Err.Number & "Desc : " & Err.Description
    Resume Exit_cboProductID_GotFocus

End Sub

0
 
demoniumzAuthor Commented:
i must  write these in  the form  code sure?
0
 
josephwalshCommented:
Right click on the product combo box, click properties, click events tab, click on got focus, from drop down click event procedure.
The vb code will appear and you can paste the above into it.
Make sure Private Sub cboProductID_GotFocus() & End Sub are not duplicated
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
demoniumzAuthor Commented:
click events tab, click on got focus, from drop down click event procedure.

i cant found it : explain pls
0
 
josephwalshCommented:
See attached picture
untitled.bmp
0
 
demoniumzAuthor Commented:
hehee this is ms office 2007 true? so  from ms acces i must add the query?
0
 
demoniumzAuthor Commented:
my form is in VB 2005 not in ms access
0
 
josephwalshCommented:
Are you using Visual Studio 2005 (VB) with MSAccess as the Data Store ?
0
 
josephwalshCommented:
Can you show me a sample of your code ?
0
 
demoniumzAuthor Commented:

ok here is all the code
ublic Class NicolaouPurchase
 
    Private Sub PurchaseBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PurchaseBindingSource.EndEdit()
        Me.PurchaseTableAdapter.Update(Me.NicolaouDBDataSet.Purchase)
 
    End Sub
   
    Private Sub PurchasedetailsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PurchasedetailsBindingSource.EndEdit()
        Me.PurchasedetailsTableAdapter.Update(Me.NicolaouDBDataSet.Purchasedetails)
 
    End Sub
    Private Sub NicolaouPurchase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      
    End Sub
 
 
    Private Sub Addpr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addpr.Click
        Dim bsource As BindingSource = Me.PurchasedetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("PurchaseDetails").NewRow
        dr("Purchaseid") = PurchaseIDTextBox.Text
        dr("Productid") = ProductIDComboBox1.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox1.Text
        dr("Quantity") = QuantityTextBox1.Text
        dr("Productname") = ProductNameTextBox1.Text
 
        dr("Total") = Convert.ToString(UnitPriceTextBox1.Text.ToString()) * Convert.ToString(QuantityTextBox1.Text.ToString())
 
        ds.Tables("PurchaseDetails").Rows.Add(dr)
 
 
        TotalSum()
    End Sub
    Private Sub TotalSum()
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In PurchasedetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * CDec(row.Cells(4).Value)
            sum += row.Cells(5).Value
        Next
        Me.TotalTextBox.Text = sum
        Me.TotalTextBox.Text = sum.ToString("¬0.00")
 
 
        PurchasedetailsDataGridView.Columns(5).DefaultCellStyle.Format = ("¬0.00")
    End Sub
 
    
 
    Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
        Me.NicolaouDBDataSet.Purchasedetails.Clear()
        TotalTextBox.Text = String.Empty
        PurchaseBindingSource.AddNew()
 
    End Sub
 
 
 
    Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
        PurchasedetailsBindingSource.MoveNext()
    End Sub
 
    Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
        PurchasedetailsBindingSource.MovePrevious()
 
    End Sub
 
    Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
        PurchasedetailsBindingSource.MoveLast()
    End Sub
 
    Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
        PurchasedetailsBindingSource.MovePrevious()
    End Sub
 
    Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
        PurchasedetailsBindingSource.RemoveCurrent()
    End Sub
 
    Private Sub delbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click
 
        PurchasedetailsDataGridView.Rows.Remove(PurchasedetailsDataGridView.CurrentRow)
 
        TotalSum()
    End Sub
 
    Private Sub clearbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbut.Click
        Me.NicolaouDBDataSet.Purchasedetails.Clear()
    End Sub
 
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Purchasedetails' table. You can move, or remove it, as needed.
        Me.PurchasedetailsTableAdapter.Fill(Me.NicolaouDBDataSet.Purchasedetails)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NicolaouDBDataSet.Products)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Purchase' table. You can move, or remove it, as needed.
        Me.PurchaseTableAdapter.Fill(Me.NicolaouDBDataSet.Purchase)
 
    End Sub
 
    
 
    
 
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
    End Sub
End Class

Open in new window

0
 
demoniumzAuthor Commented:
is not easy to   fix it to many errors
0
 
demoniumzAuthor Commented:
Error      2      Handles clause requires a WithEvents variable defined in the containing type or one of its base types.      D:\s\Nicolaou\NicolaouPurchase.vb      131      105      Nicolaou

Error      1      Name 'cShared' is not declared.      D:\s\Nicolaou\NicolaouPurchase.vb      20      33      Nicolaou



Public Class NicolaouPurchase
 
    Private Sub PurchaseBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PurchaseBindingSource.EndEdit()
        Me.PurchaseTableAdapter.Update(Me.NicolaouDBDataSet.Purchase)
 
    End Sub
   
    Private Sub PurchasedetailsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PurchaseBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.PurchasedetailsBindingSource.EndEdit()
        Me.PurchasedetailsTableAdapter.Update(Me.NicolaouDBDataSet.Purchasedetails)
 
    End Sub
    Private Sub NicolaouPurchase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Cursor = Cursors.WaitCursor
 
        'Loads the data
        Dim dsData As DataSet = cShared.CreateDataSet()
 
        'Creates a relation between the 2 DataTables
        dsData.Relations.Add("relsuppliersproducts", _
                        dsData.Tables("suppliers").Columns("supplierID"), _
                        dsData.Tables("Products").Columns("Productid"))
 
        'Binds the combos
        With SupplierIDComboBox
            .DisplayMember = "contactname.Description"
            .ValueMember = "supplierid"
            .DataSource = SuppliersBindingSource
        End With
 
        With ProductIDComboBox1
            .DisplayMember = "productname.relsuppliersproducts.Description"
            .ValueMember = "Poductid"
            .DataSource = ProductsBindingSource
        End With
 
        Me.Cursor = Cursors.Default
    End Sub
 
 
    Private Sub Addpr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addpr.Click
        Dim bsource As BindingSource = Me.PurchasedetailsDataGridView.DataSource
        Dim ds As DataSet = DirectCast(bsource.DataSource, DataSet)
 
        Dim dr As DataRow = ds.Tables("PurchaseDetails").NewRow
        dr("Purchaseid") = PurchaseIDTextBox.Text
        dr("Productid") = ProductIDComboBox1.SelectedValue
        dr("UnitPrice") = UnitPriceTextBox1.Text
        dr("Quantity") = QuantityTextBox1.Text
        dr("Productname") = ProductNameTextBox1.Text
 
        dr("Total") = Convert.ToString(UnitPriceTextBox1.Text.ToString()) * Convert.ToString(QuantityTextBox1.Text.ToString())
 
        ds.Tables("PurchaseDetails").Rows.Add(dr)
 
 
        TotalSum()
    End Sub
    Private Sub TotalSum()
        Dim sum As Decimal = 0
        For Each row As DataGridViewRow In PurchasedetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(3).Value * CDec(row.Cells(4).Value)
            sum += row.Cells(5).Value
        Next
        Me.TotalTextBox.Text = sum
        Me.TotalTextBox.Text = sum.ToString("¬0.00")
 
 
        PurchasedetailsDataGridView.Columns(5).DefaultCellStyle.Format = ("¬0.00")
    End Sub
 
    
 
    Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
        Me.NicolaouDBDataSet.Purchasedetails.Clear()
        TotalTextBox.Text = String.Empty
        PurchaseBindingSource.AddNew()
 
    End Sub
 
 
 
    Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
        PurchasedetailsBindingSource.MoveNext()
    End Sub
 
    Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
        PurchasedetailsBindingSource.MovePrevious()
 
    End Sub
 
    Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
        PurchasedetailsBindingSource.MoveLast()
    End Sub
 
    Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
        PurchasedetailsBindingSource.MovePrevious()
    End Sub
 
    Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
        PurchasedetailsBindingSource.RemoveCurrent()
    End Sub
 
    Private Sub delbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click
 
        PurchasedetailsDataGridView.Rows.Remove(PurchasedetailsDataGridView.CurrentRow)
 
        TotalSum()
    End Sub
 
    Private Sub clearbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbut.Click
        Me.NicolaouDBDataSet.Purchasedetails.Clear()
    End Sub
 
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Purchasedetails' table. You can move, or remove it, as needed.
        Me.PurchasedetailsTableAdapter.Fill(Me.NicolaouDBDataSet.Purchasedetails)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NicolaouDBDataSet.Products)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Suppliers' table. You can move, or remove it, as needed.
        Me.SuppliersTableAdapter.Fill(Me.NicolaouDBDataSet.Suppliers)
        'TODO: This line of code loads data into the 'NicolaouDBDataSet.Purchase' table. You can move, or remove it, as needed.
        Me.PurchaseTableAdapter.Fill(Me.NicolaouDBDataSet.Purchase)
 
    End Sub
 
    
    Private Sub btnShowValues_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowValues.Click
        Dim intSelectedproductid As Integer
        Dim intSelectedsupplierid As Integer
 
        If SupplierIDComboBox.SelectedValue Is Nothing Then
            intSelectedsupplierid = -1
        Else
            Try
                intSelectedsupplierid = Convert.ToInt32(SupplierIDComboBox.SelectedValue)
            Catch ex As Exception
                intSelectedsupplierid = -1
            End Try
        End If
 
        If ProductIDComboBox1.SelectedValue Is Nothing Then
            intSelectedproductid = -1
        Else
            Try
                intSelectedproductid = Convert.ToInt32(ProductIDComboBox1.SelectedValue)
            Catch ex As Exception
                intSelectedproductid = -1
            End Try
        End If
 
        MessageBox.Show("The ID of the selected Country is : " + intSelectedsupplierid.ToString + Environment.NewLine + _
                        "The ID of the selected State/Province is : " + intSelectedproductid.ToString, _
                        "Demo application", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
 
    Private Sub ProductIDComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductIDComboBox1.SelectedIndexChanged
 
    End Sub
End Class
    
 
    

Open in new window

0
 
demoniumzAuthor Commented:
my  dataset is NicolaouDBDataSet i am  using database from ms access 2003 llinked to vb 2005
0
 
Éric MoreauSenior .Net ConsultantCommented:
cShared is the name of the class I use to create the in-memory dataset.

All your tableAdpater's Fill method should be moved to the Load event.
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>is not easy to   fix it to many errors

you surely don't have errors in the original demo (before you start modifying it).
0
 
demoniumzAuthor Commented:
in the original demo is not  have error  in mine yes
0
 
demoniumzAuthor Commented:
Private Sub NicolaouPurchase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Cursor = Cursors.WaitCursor

        'Loads the data

        Dim Nicolaoudb As DataSet = cShared.CreateDataSet()
        'Creates a relation between the 2 DataTables
        Nicolaoudb.Relations.Add("relsuppliersproducts", _
                        Nicolaoudb.Tables("suppliers").Columns("supplierID"), _
                        Nicolaoudb.Tables("Products").Columns("Productid"))

        'Binds the combos
        With SupplierIDComboBox
            .DisplayMember = "contactname.Description"
            .ValueMember = "supplierid"
            .DataSource = SuppliersBindingSource
        End With

        With ProductIDComboBox1
            .DisplayMember = "productname.relsuppliersproducts.Description"
            .ValueMember = "Poductid"
            .DataSource = ProductsBindingSource
        End With

        Me.Cursor = Cursors.Default
    End Sub

cshared is not decleare!!!!!!!!!!!!!!!!!!!!!!!
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>cshared is not decleare

again, cShared is my class that contains the CreateDataset. You don't have it so replace that line with your Fills method.
0
 
demoniumzAuthor Commented:
This constraint cannot be enabled as not all values have corresponding parent values.
 
NicolaouDBDataSet.Relations.Add("relsuppliersproducts", _
                        NicolaouDBDataSet.Tables("suppliers").Columns("supplierID"), _
                        NicolaouDBDataSet.Tables("Products").Columns("Productid"))

my table is suppliers and products  dataset is NIcolaouDB

THE two combobox is supplieridcombobox and productid combobox
0
 
demoniumzAuthor Commented:
i have a combox and 2-3 textboxes that moved from combobox is these the problem?
0
 
Éric MoreauSenior .Net ConsultantCommented:
the relation you create has to bind fields with the same values. Your Products table surely have a SupplierID column. This is the field you need to relate:

NicolaouDBDataSet.Relations.Add("relsuppliersproducts", _
                        NicolaouDBDataSet.Tables("suppliers").Columns("supplierID"), _
                        NicolaouDBDataSet.Tables("Products").Columns("supplierID"))
0
 
demoniumzAuthor Commented:
A relation already exists for these child columns.
0
 
Éric MoreauSenior .Net ConsultantCommented:
a relation in the database or in the dataset? it has to exist in the dataset. if it exist, just provide appropriate names to the binding of the combobox and it will work.
0
 
demoniumzAuthor Commented:
can i  uploadi it here  to help me fix it
0
 
Éric MoreauSenior .Net ConsultantCommented:
You have a fully working example. You should be able to do it. If you replace the name of the fields and relations, it just works. If you upload it, I won't be able to test it as I don't have the matching database!
0
 
demoniumzAuthor Commented:
i can upload  also the database

0
 
Éric MoreauSenior .Net ConsultantCommented:
have you seriously tried to fix it yourself? it should be really simple. a lot of people have downloaded my demo and made it fit their own needs. you can try to upload it.

btw, this become consultation, where do I send the bill ;)
0
 
demoniumzAuthor Commented:
The aplication i cant upload it now cause no time  i must go to work tonight i upload it thnks
NicolaouDB.mdb
0
 
demoniumzAuthor Commented:
lol sent it to me the bill
0
 
demoniumzAuthor Commented:
i upload my  aplications pls help me to fix it

Regards demoniumz
s.zip
0
 
Éric MoreauSenior .Net ConsultantCommented:
are you kidding me? 16.5 mb?!?!?! If I open this, I will have to send an invoice for real!

Can you create a single form with your dataset already opened?
0
 
demoniumzAuthor Commented:
can i copy the form   to another aplication? yes> how?
0
 
Éric MoreauSenior .Net ConsultantCommented:
open Windows Explorer and copy the 2 files to another folder.
0
 
demoniumzAuthor Commented:
the 2 files which?
0
 
Éric MoreauSenior .Net ConsultantCommented:
for how long have you been using .Net?

yourForm.vb + yourform.designer.vb
0
 
demoniumzAuthor Commented:
for 1 year now

http://rapidshare.com/files/233040805/New_Folder.zipx.html

here downlad it please
0
 
demoniumzAuthor Commented:
for 1 year now

http://rapidshare.com/files/233040805/New_Folder.zipx.html

here downlad it please
0
 
demoniumzAuthor Commented:
thnks for the help
0
 
Éric MoreauSenior .Net ConsultantCommented:
is zipx a special format?

I tried to rename it as .zip and I cannot extract any files from it.
0
 
demoniumzAuthor Commented:
0
 
Éric MoreauSenior .Net ConsultantCommented:
you haven't created something I can work from! I asked for you to create a single form application with your dataset already opened.

And I continue to say that if you are a programmer, you should be able to replace the name of the columns from my example with yours.
0
 
demoniumzAuthor Commented:
waita littile i have poblem with save n a the form please
0
 
demoniumzAuthor Commented:
http://rapidshare.com/files/235853093/Nicolaou.rar.html

Here is the new upload i make  pls help

Regards demoniumz
0
 
Éric MoreauSenior .Net ConsultantCommented:
I got it working. I have completely reused your dataset and the relation that was existing.

First, the supplier value in the products table was empty! I had to fill this column directly in the database.

Then I wasn't really sure about your 2 combos. So I have added 2 new combo box to the form. I have named the first one as cboSupplier and the second one as cboProduct (without modifying any other properties).

Finally, I have added this snippet to the Load event:

        With Me.cboSupplier 
            .DisplayMember = "Suppliers.CompanyName"
            .ValueMember = "SupplierID"
            .DataSource = Me.NicolaouDBDataSet
        End With
        With Me.cboProduct 
            .DisplayMember = "Suppliers.SuppliersProducts.ProductName"
            .ValueMember = "ProductID"
            .DataSource = Me.NicolaouDBDataSet
        End With

Open in new window

0
 
demoniumzAuthor Commented:
can u explain me something please
1.What are u menawith these??
First, the supplier value in the products table was empty! I had to fill this column directly in the database.
You mean that no  supplier exist in  the database? so you add a new one?

2.Then I wasn't really sure about your 2 combos. So I have added 2 new combo box to the form. I have named the first one as cboSupplier and the second one as cboProduct (without modifying any other properties).

You mean the combobox i add is  in wrong way how i can corected?And how you add  . DisplayMember = "Suppliers.SuppliersProducts.ProductName

3 can u upload back the solution so i can  see it please??

Thnks for the help i apreciate.When  i try the solution with  my combobox i get  in the two comboboxs
System.Data.DataviewManagerListItemTypeDescriptor why>?


0
 
demoniumzAuthor Commented:
please upload  the solution  online so  i can  check my problem i can  move the two combobox  but the  textboxes that moved bedore  can t changed.

Regards demoniums

ps see to be errors in the type of i  make the relation  because is like something they stack i cant close the form (must go to run in vb  to stop the form.Please upload the solution
0
 
demoniumzAuthor Commented:
Now is working 100% but the problem is that i need to move the textboxes that they moved as before so  i  can see the unit price and etc how?
0
 
demoniumzAuthor Commented:
emoreau when the combobox  select for example Royal&rothmans to see the details of the products and the company that belong to it?????
0
 
Éric MoreauSenior .Net ConsultantCommented:
ok apparently you got it working so I won't need to upload anything.

Using the technique I have used here (to set the DisplayMember on the relation), the order is ALWAYS from the parent to child (Suppliers to Products in your case).

If you need to modify that, you will need to use solution #2 from my article. Handle the SelectedIndexChanged event of the product combo to fill the supplier combo.
0
 
demoniumzAuthor Commented:
i understand you but how  i set it  when the combobox Royals&Rothmans selected to appera the details of the supplier in the textboxes?

That i ask can u explain me?
0
 
Éric MoreauSenior .Net ConsultantCommented:
I never bind controls like you do.

in the SelectedIndexChanged of the supplier combo, fill the textbox you need. it currently does not follow because you manually feed the combo. Otherwise, you would need to synchronize the binding source but, as I said, I never bind controls like you do.
0
 
demoniumzAuthor Commented:
In the SelectedIndexChanged of the supplier combo, fill the textbox you need what are u mean  fill ?how to  fill it?
And how i  synchronize the binding source?
0
 
demoniumzAuthor Commented:
apologize but i am new to vb
0
 
Éric MoreauSenior .Net ConsultantCommented:
I have spent enough time on this and I don't see the end of all your questions. You asked about the combo box and we are now at textbox and databinding. sorry but I don't have that much time.
0
 
demoniumzAuthor Commented:
ok ok
0
 
demoniumzAuthor Commented:
Hello again apolozise i  ask  again but i need to know if your in  the situation to  help me  complete something.I fill  the combobox the Supplier combobox and the solution you provide to me is working also i  make the textboxes to work for supplier but the textboxes for Productid combobox is not moved can u explain me.

Also the Image in the supplier that i want to change is not changed why?>

Thnks for help if you are not in situation to help me i close  the question now

Regards demoniumz

 Private Sub SupplierIDComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SupplierIDComboBox.SelectedIndexChanged
        If Me.SupplierIDComboBox.SelectedIndex <> -1 Then
 
            Dim dr As DataRow = Me.NicolaouDBDataSet.Suppliers.Rows.Find(Me.SupplierIDComboBox.SelectedValue)
            If dr IsNot Nothing Then
                Me.SupplierIDTextBox.Text = dr.Item(0).ToString
                Me.ContactTitleTextBox.Text = dr.Item(1).ToString
                Me.CompanyNameTextBox.Text = dr.Item(2).ToString
                Me.PhotoPictureBox = dr.Item(3).ToString
            End If
 
        End If
 
    End Sub
 
    Private Sub ProductIDComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductIDComboBox.SelectedIndexChanged
        If Me.ProductIDComboBox.SelectedIndex <> -1 Then
 
            Dim dr As DataRow = Me.NicolaouDBDataSet.Products.Rows.Find(Me.ProductIDComboBox.SelectedValue)
            If dr IsNot Nothing Then
                Me.DescriptionTextBox.Text = dr.Item(0).ToString
 
 
            End If
 
        End If
    End Sub

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
for your picturebox, you need to convert to byte array to an image:

                If Convert.IsDBNull(dr.Item("Photo")) Then
                    Me.PhotoPictureBox.Image = Nothing
                Else
                    Me.PhotoPictureBox.Image = ConvertTo(dr.Item("Photo"))
                End If

    Public Overloads Function ConvertTo(ByVal ImageArray As Byte()) As System.Drawing.Image
        Dim objMS As New System.IO.MemoryStream

        objMS.Write(ImageArray, 0, ImageArray.Length)
        Try
            ConvertTo = System.Drawing.Image.FromStream(objMS)
        Catch ae As System.ArgumentException
            Return Nothing
        End Try
    End Function
0
 
demoniumzAuthor Commented:
for the other textboxes
0
 
Éric MoreauSenior .Net ConsultantCommented:
It is working if you set the to the correct item:

        If Me.ProductIDComboBox.SelectedIndex <> -1 Then

            Dim dr As DataRow = Me.NicolaouDBDataSet.Products.Rows.Find(Me.ProductIDComboBox.SelectedValue)
            If dr IsNot Nothing Then
                'Me.DescriptionTextBox.Text = dr.Item(0).ToString
                Me.DescriptionTextBox.Text = dr.Item("ProductName").ToString
                Me.UnitPriceTextBox.Text = dr.Item("UnitPrice").ToString
                Me.QuantityTextBox.Text = dr.Item("QtyPerUnit").ToString

            End If

        End If
0
 
demoniumzAuthor Commented:
Not working
0
 
demoniumzAuthor Commented:
The Product textboxes is not moved nothing working except Productidcombobox
0
 
Éric MoreauSenior .Net ConsultantCommented:
can you reupload your .zip file HERE and tell me EXACTLY what is not working?
0
 
demoniumzAuthor Commented:
Yes ofcourse i can reupload it but  The textboxes that needed in order to insert  a product in the datagridview in the form is not work only the Productidcombobox.

ps in  my project the relation from suplier to productid combobox is working here in example only suplieridcombobox appea to working

download from herehttp://rapidshare.com/files/236966381/Nicolaou.zipx.html
0
 
demoniumzAuthor Commented:
is a problrm with  winzip so  try to download to  rar from here please
I reupload it  now here

http://rapidshare.com/files/236968930/Nicolaou.rar.html
0
 
Éric MoreauSenior .Net ConsultantCommented:
I have reached the limit of a free account. Upload it HERE.
0
 
demoniumzAuthor Commented:
i have problem with winzip and winrar to upload it here so i upload it in mediafire  please download from there apologize for any problems

http://uploading.com/files/4OMC0S3S/Nicolaou.rar.html
0
 
Éric MoreauSenior .Net ConsultantCommented:
What is the problem exactly? Your textbox and your image seems to work fine.
0
 
demoniumzAuthor Commented:
Yea the textboxes from the supplieridcombobox is work  fine.You see  bellow datagrid view the Product id combobox?They are some textboxes Productname Product Quantity and etc these textboxes before is movved in order  to add a product inside the datagridview now is not worked.

I want to display the details of each  product  as the Supplier textboxes
0
 
Éric MoreauSenior .Net ConsultantCommented:
when I select a product in the Product combo, the name, description and price are changing in the textboxes.

Anyway, it is not related to the original question about the 2 comboboxes.
0
 
demoniumzAuthor Commented:
When  you selected a suplier  from the combobox1 and the suplier2 display the product that belong to the supplier the  name description and price is not changing that i  ask  why
0
 
demoniumzAuthor Commented:
Apologize here i corect what i  tell before

you selected a suplier  from the combobox1 and the combobox2 display the product that belong to the supplier the textboxes   name description and price is not changing that i  ask  why
0
 
Éric MoreauSenior .Net ConsultantCommented:
I don't understand. In the last sample you sent, the price is changing.

Also, what are combobox1 and combobox2 refering to? You have no controls with that name.

In order to help, can I ask you to make yourself clear. Without clear indication I am losing my time.
0
 
demoniumzAuthor Commented:
ok wait
0
 
demoniumzAuthor Commented:
ok first of all apologize for the sample i sent wrong.but the Product id combobox is changed becase if you see is using data bound  items if not and use  the code  you provide the  textboxes bellow the datagridview is not changed that i mean  all this time
0
 
demoniumzAuthor Commented:
give me an example code how to  fill  a combox with 2-3 textboxes please
0
 
Éric MoreauSenior .Net ConsultantCommented:
I don't understand why you want that. You have already have that.

I have also provided this code which does exactly what that:
        If Me.ProductIDComboBox.SelectedIndex <> -1 Then

            Dim dr As DataRow = Me.NicolaouDBDataSet.Products.Rows.Find(Me.ProductIDComboBox.SelectedValue)
            If dr IsNot Nothing Then
                'Me.DescriptionTextBox.Text = dr.Item(0).ToString
                Me.DescriptionTextBox.Text = dr.Item("ProductName").ToString
                Me.UnitPriceTextBox.Text = dr.Item("UnitPrice").ToString
                Me.QuantityTextBox.Text = dr.Item("QtyPerUnit").ToString

            End If

        End If

Finally, I can tell that whatever I provide you won't be good! It seems that everything I have provided is not. I never spend so much time on a single question.
0
 
demoniumzAuthor Commented:
Yea  can u  explain me why the  suplierid combobox and the textboxes is working the relation  between the Supplieridcombobox and the product id combobox is working fantastic BUT the textboxes that  belong to Product id is not changed even  i have add this code you   give ABOVE

can u  understand me ?
0
 
demoniumzAuthor Commented:
to Product id combobox  is not changed even  i have add this code you   give ABOVE
0
 
Éric MoreauSenior .Net ConsultantCommented:
you cannot bind the textboxes to the dataset. you would need to bind them to the relations. beleive me it is a lot easier to manually feed them (like the code just pasted).

>>to Product id combobox  is not changed even  i have add this code you   give ABOVE

In the last code you sent me, the SelectedIndexChanged event was not handled. I have already provided that code.
0
 
demoniumzAuthor Commented:
These is  is the form  after i try to explain  u  i wish to understand me
untitled.PNG
0
 
demoniumzAuthor Commented:
can u explain me how i  bind it manually?
0
 
demoniumzAuthor Commented:
oups ok  sorry  how to   to bind them to the relations what you mean  with that.Itry it manually  with the code  you  give me before but is not work the textboxes  belong to product id combobox
0
 
Éric MoreauSenior .Net ConsultantCommented:
you don't want to bind manually, you would have the same problem.

you better assign the values manually in the SelectedIndexChange event.
0
 
demoniumzAuthor Commented:
you better assign the values manually in the SelectedIndexChange event

these code is what i must used?

      If Me.ProductIDComboBox.SelectedIndex <> -1 Then

            Dim dr As DataRow = Me.NicolaouDBDataSet.Products.Rows.Find(Me.ProductIDComboBox.SelectedValue)
            If dr IsNot Nothing Then
                'Me.DescriptionTextBox.Text = dr.Item(0).ToString
                Me.DescriptionTextBox.Text = dr.Item("ProductName").ToString
                Me.UnitPriceTextBox.Text = dr.Item("UnitPrice").ToString
                Me.QuantityTextBox.Text = dr.Item("QtyPerUnit").ToString

            End If

        End If
0
 
demoniumzAuthor Commented:
Finally  i  am  understand what happened:)

 Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
 Private Sub ComboBox2_SelectedIndexChanged

When  i  choose  from the combobox 2 that appear the product  belong to suplier if i choose it the textboxes changed and is working 100%

Apologize and thnks for Help :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 54
  • 27
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now