Results 1 to 8 of 8

Thread: [RESOLVED] DGV works, but it seems to me is shouldn't

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Resolved [RESOLVED] DGV works, but it seems to me is shouldn't

    I have a DGV that displays all vendors that are associated with an part (I call the vendors sources and parts/components/etc. items). It is working just fine, but there are a couple of things about it I do not understand. Since items are in one table and sources in another I have a third table that links the two tables together. I use a Join query when I want to display for these tables. In this case, I want to see all of the sources associated with a defined item, in this case the item with the ID 100000021

    I also use this form for other things, so the DGV parameters are all defined in the code

    Code:
    SELECT        tblSupplyMaster.intSiTechID, tblSupplyMaster.strSupplierName
    FROM            ((lnkVendorSpec INNER JOIN
                             tblItemMaster ON tblItemMaster.intSiTechID = lnkVendorSpec.intSiTechItemID) INNER JOIN
                             tblSupplyMaster ON tblSupplyMaster.intSiTechID = lnkVendorSpec.intSiTechSupplyID)
    WHERE        (lnkVendorSpec.intSiTechItemID = ?)
    Name:  vendor.jpg
Views: 284
Size:  60.6 KB

    This is exactly what is supposed to occur. However, it took me awhile to get the display to present as required. Here is the code for the DGV

    Code:
                With dgvElementList
                    '.ReadOnly = False
                    'Columns
                    .Size = New Size(480, 353)
                    .Location = New Point(13, 195)
                    'Cells
                    .DataSource = _MasterBase5_0DataSet
                    .DataMember = "tblItemMaster"
                    .Columns(0).Visible = True
                    .Columns(0).Width = 100
                    .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                    .Columns(0).DisplayIndex = 0
                    .Columns(1).Visible = False
                    .Columns(2).Visible = False
                    .Columns(3).Visible = False
                    .Columns(4).Visible = False
                    .Columns(5).Visible = False
                    .Columns(6).Visible = False
                    .Columns(7).Visible = False
                    .Columns(8).Visible = False
                    .Columns(9).Visible = False
                    .Columns(10).Visible = False
                    .Columns(11).Visible = False
                    .Columns(12).Visible = False
                    .Columns(13).Visible = True
                    .Columns(13).Width = 375
                    .Columns(13).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                    .Columns(13).DisplayIndex = 1
                End With
    The Item table has 12 columns in it and the Supplier table has 12 columns. So what I do not understand is why is column 0 displaying the ID number for the supplier and column 13 the supplier name? In the select above, I only have the two columns I am interested in from the supplier table, but based on this it appears to me that the Item ID column does not exist, as far as the code goes, and has been replaced by that ID column for the supplier then the Supplier Name column was added as an additional column.

    As stated previously, this displays exactly what is required, but the code for the DGV does not even come close to being what I would expect it to be.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: DGV works, but it seems to me is shouldn't

    Double check that _MasterBase5_0DataSet is the data set you think it is, and that tblItemMaster is what you think it is.

    My guess is you're telling it to look at a table with 13 columns, not the results of your query.

    If you're using a TableAdapter/DataAdapter I'd expect you to be calling Fill() on some data set, but that resultset shouldn't really be mapped to tblItemMaster: it's just a resultset.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV works, but it seems to me is shouldn't

    Sitten, I will check all of that. However, the dataset is the only one I have. The query is in the table adapter of tblItemMaster and is called in the load event as:

    Code:
    TblItemMasterTableAdapter.FillItemJoinQuery(Me._MasterBase5_0DataSet.tblItemMaster, glbintSiTechID)
    I suspect, from what you are telling me, is I should setup the query in tblSupplyMaster, and make the call to that query in that tableadapter. Assuming that to be the case, that actually sounds more logical than what I have right now.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: DGV works, but it seems to me is shouldn't

    I'm confused, you setup a dgv with 14 columns but your SQL only retrieves 2. If that Sql statement is what fills your datatable then that's all the columns your going to get.

  5. #5
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: DGV works, but it seems to me is shouldn't

    When it comes to hiding many columns you can run through them like so: (just my 2 cents)
    Code:
            For Each DGVCol As DataGridViewColumn In Datagridview1.Columns
                DGVCol.Visible = False
            Next
            With Datagridview1
                .Columns("SomeCol").Visible = True
            End With

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: DGV works, but it seems to me is shouldn't

    I only have the two columns I am interested in from the supplier table, but based on this it appears to me that the Item ID column does not exist, as far as the code goes, and has been replaced by that ID column for the supplier then the Supplier Name column was added as an additional column.
    Maybe to make it clear,

    That is exactly what your Sql statement retrieves "SELECT tblSupplyMaster.intSiTechID, tblSupplyMaster.strSupplierName"
    You don't Select the ItemMaster Id.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV works, but it seems to me is shouldn't

    Wes,

    Wes, I can see where that might seem confusing. However, I have found that no matter what is in your select, every column in the table adapter will be visible unless specified otherwise.

    Sitten,

    I set the query up in the tblSupplyMaster and used that as my data member and now the code and the display requirements indeed match. What I previously had worked, as far as the display requirements, but it did not match with what was coded. Now the query and code look like this:

    Code:
    SELECT        tblSupplyMaster.intSiTechID, tblSupplyMaster.strSupplierName
    FROM            ((lnkVendorSpec INNER JOIN
                             tblSupplyMaster ON tblSupplyMaster.intSiTechID = lnkVendorSpec.intSiTechSupplyID) INNER JOIN
                             tblItemMaster ON tblItemMaster.intSiTechID = lnkVendorSpec.intSiTechItemID)
    WHERE        (lnkVendorSpec.intSiTechItemID = ?)
    Code:
                With dgvElementList
                    '.ReadOnly = False
                    'Columns
                    .Size = New Size(480, 353)
                    .Location = New Point(13, 195)
                    'Cells
                    .DataSource = _MasterBase5_0DataSet
                    .DataMember = "tblSupplyMaster"
                    .Columns(0).Visible = True
                    .Columns(0).Width = 100
                    .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                    .Columns(0).DisplayIndex = 0
                    .Columns(1).Visible = False
                    .Columns(2).Visible = False
                    .Columns(3).Visible = True
                    .Columns(3).Width = 375
                    .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                    .Columns(3).DisplayIndex = 1
                    .Columns(4).Visible = False
                    .Columns(5).Visible = False
                    .Columns(6).Visible = False
                    .Columns(7).Visible = False
                    .Columns(8).Visible = False
                    .Columns(9).Visible = False
                    .Columns(10).Visible = False
                    .Columns(11).Visible = False
                    .Columns(12).Visible = False
                End With
    Wes, I tried your 2 cents worth and the additional columns still showed. Could you explain what I might have done wrong? Here is what it looks like:

    Code:
            For Each DGVCol As DataGridViewColumn In dgvElementList.Columns
                DGVCol.Visible = False
            Next
            With dgvElementList
                '.ReadOnly = False
                'Columns
                .Size = New Size(480, 353)
                .Location = New Point(13, 195)
                'Cells
                .DataSource = _MasterBase5_0DataSet
                .DataMember = "tblSupplyMaster"
                .Columns(0).Visible = True
                .Columns(0).Width = 100
                .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns(0).DisplayIndex = 0
                .Columns(3).Visible = True
                .Columns(3).Width = 375
                .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                .Columns(3).DisplayIndex = 1
            End With

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: DGV works, but it seems to me is shouldn't

    That was KPMC's 2 cents, not Wes. Sorry

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