The value of the first 2 columns for all the rows are the same.  how can i use to display the info look something like this

Posted on 2004-10-29
Last Modified: 2012-05-05
i called a sql query to a view and return the records below.

PID     Description     PInfoName     pInfoValue
888     Portable PC     Model ID     p909
888     Portable PC     CPU          P4 3.4G
888     Portable PC     Memory          2G RAM

The value of the first 2 columns for all the rows are the same.  how can i use to display the info look something like this
General Info:
PID     Description
888     Portable PC

Product details info:
Model ID     p909
CPU            P4 3.4G
Memory      2G RAM    
Question by:musclejack
    LVL 19

    Expert Comment

    You are taking the case of only one item
    i.e. when PID=888
    what if there are 6 records 3 for PID=888 as you have shown
    and three for PID=999

    Then how would you like to show???
    One way is you canhave the PID and Description in one dataGrid and the rest info on the other datagrid
    When user selects a row in top Datagrid the bottom one gets populated with details of the particular PID


    you can have a Combobox and a Dtatgrid


    Author Comment

    can u give me an simple example?  thx
    LVL 19

    Expert Comment

    OK here goes...

    What I have done is Add One ComboBox to a Form and Named it CmbPID
    And Added a dataGrid called DetailsdataGrid

    Then, At Form level declare

        Dim DTDetails As DataTable
        Dim ConStr As String="Provider=..... YOUR CONNECTION STRING ...."

        'On Form Load Call the Function FillData
        Private Sub FrmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub

      'FillData Loads the PID and the Description in a Combo Box. It loads all the unique PIDs
        Private Sub FillData()
            Dim DR As OleDbDataReader
            Dim Cn As OleDbConnection = New OleDbConnection(ConStr)
            Dim Cmd As OleDbCommand = New OleDbCommand("Select Distinct PID, Description From Mytable", Cn) 'Remember the keyword DISTINCT
            'The Qurery will change based on the exact table and Column Names
            DR = Cmd.ExecuteReader
            Do While DR.Read
                Me.CmbPID.Items.Add(DR(0) & " " & Dr(1))
        End Sub

       'Now Whenever you select a PID from the Combo, This event is fired. here we fill the DataGrid with the
    'Details of that particular PID which was selected in the Combo
        Private Sub CmbPID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbPID.SelectedIndexChanged
            DTDetails = New DataTable
            Dim DA As OleDbDataAdapter = New OleDbDataAdapter("Select PInfoName,PInfoValue From Mytable Where PID='" & Me.CmbPID.Text & "'", ConStr)
            Me.DetailsDataGrid.DataSource = DTDetails
        End Sub

    That's it
    I have just assumed a Table named MyTable with 4 columns as mentioned by you
    LVL 19

    Accepted Solution

    A small background what this whole thing will do

    We'll have a form with one Combo Box and One DataGrid
    ComboBox will have All PIDs and Desctiption eg
    888 Portable PC    
    999 LapTop

    Then whenever you select an Item from the Combo Say 888, the dataGrid will show all the details of it like

    Model ID     p909
    CPU            P4 3.4G
    Memory      2G RAM  


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    913 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

    20 Experts available now in Live!

    Get 1:1 Help Now