Solved

Query  needed  vb 2005

Posted on 2009-05-13
88
291 Views
Last Modified: 2013-12-26
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
Comment
Question by:demoniumz
  • 54
  • 27
  • 5
88 Comments
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24376145
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24376294
i must  write these in  the form  code sure?
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24376396
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24376804
click events tab, click on got focus, from drop down click event procedure.

i cant found it : explain pls
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24376941
See attached picture
untitled.bmp
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24377051
hehee this is ms office 2007 true? so  from ms acces i must add the query?
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24377160
my form is in VB 2005 not in ms access
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24377188
Are you using Visual Studio 2005 (VB) with MSAccess as the Data Store ?
0
 
LVL 5

Expert Comment

by:josephwalsh
ID: 24377220
Can you show me a sample of your code ?
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24377320

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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24380626
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24382975
is not easy to   fix it to many errors
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24383093
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383111
my  dataset is NicolaouDBDataSet i am  using database from ms access 2003 llinked to vb 2005
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383162
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383168
>>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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383179
in the original demo is not  have error  in mine yes
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24383204
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383253
>>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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383324
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383358
i have a combox and 2-3 textboxes that moved from combobox is these the problem?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383430
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383648
A relation already exists for these child columns.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383724
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383799
can i  uploadi it here  to help me fix it
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383887
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24383951
i can upload  also the database

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24383979
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24384045
The aplication i cant upload it now cause no time  i must go to work tonight i upload it thnks
NicolaouDB.mdb
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24384051
lol sent it to me the bill
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24387543
i upload my  aplications pls help me to fix it

Regards demoniumz
s.zip
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24387741
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24389164
can i copy the form   to another aplication? yes> how?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24389236
open Windows Explorer and copy the 2 files to another folder.
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24389467
the 2 files which?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24389625
for how long have you been using .Net?

yourForm.vb + yourform.designer.vb
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24389896
for 1 year now

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

here downlad it please
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24389897
for 1 year now

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

here downlad it please
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24390190
thnks for the help
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24391171
is zipx a special format?

I tried to rename it as .zip and I cannot extract any files from it.
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24393049
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24394135
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24429007
waita littile i have poblem with save n a the form please
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:demoniumz
ID: 24448212
http://rapidshare.com/files/235853093/Nicolaou.rar.html

Here is the new upload i make  pls help

Regards demoniumz
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 24449517
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24457111
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24457185
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24457190
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24457220
emoreau when the combobox  select for example Royal&rothmans to see the details of the products and the company that belong to it?????
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24457582
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24458447
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24458460
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24458472
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24458473
apologize but i am new to vb
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24458480
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24458998
ok ok
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24461431
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24462326
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24462751
for the other textboxes
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24462979
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24463066
Not working
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24463119
The Product textboxes is not moved nothing working except Productidcombobox
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24463531
can you reupload your .zip file HERE and tell me EXACTLY what is not working?
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24465042
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24465102
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24465711
I have reached the limit of a free account. Upload it HERE.
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24465874
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24465946
What is the problem exactly? Your textbox and your image seems to work fine.
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24466006
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24466040
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24466125
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24466152
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24466758
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24468242
ok wait
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24468472
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24468511
give me an example code how to  fill  a combox with 2-3 textboxes please
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24468533
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24468578
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24468582
to Product id combobox  is not changed even  i have add this code you   give ABOVE
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24468623
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24468654
These is  is the form  after i try to explain  u  i wish to understand me
untitled.PNG
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24468669
can u explain me how i  bind it manually?
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24468702
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24468768
you don't want to bind manually, you would have the same problem.

you better assign the values manually in the SelectedIndexChange event.
0
 
LVL 1

Author Comment

by:demoniumz
ID: 24468783
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
 
LVL 1

Author Comment

by:demoniumz
ID: 24469143
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now