Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

don't display copy vb.net 2008

Posted on 2009-05-07
9
Medium Priority
?
169 Views
Last Modified: 2012-05-06
i have below table witn many row in DB

BrandID Brand
1             Honda
2             Toyota

ModelID BrandID Model
1                1          CRV
2                1          Civic
3                1           Accord


when i use below sql
select * from brand,model where Brand.BrandID=Model.BrandID
it show below in Datagribview

Honda           CRV
Honda           Civic
Honda           Accord


how to show like below in datagridview

Honda        CRV
                   Civic
                   Accord
0
Comment
Question by:aarontham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24324162
What about something like:
Dim current As String = DataGridView1.Rows(0).Cells(0).Value
 
For i As Integer = 1 To Me.DataGridView1.Rows.Count - 1   ' change DataGridView1 to the name of your DG
    If row.Cells(i).Value.ToString() = current Then
        row.Cells(i).Value = String.Empty
    Else
        current = row.Cells(i).Value.ToString()
    End If
Next

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24324177
My mistake. The indexer was on the wrong variable. Use the code below instead. You will need to change the Cells(0) to Cells(x) where x is the column index of your vehichle manufacturere name.
Dim current As String = DataGridView1.Rows(0).Cells(0).Value
 
For i As Integer = 1 To Me.DataGridView1.Rows.Count - 1   ' change DataGridView1 to the name of your DG
    If row(i).Cells(0).Value.ToString() = current Then
        row(i).Cells(0).Value = String.Empty
    Else
        current = row(i).Cells(0).Value.ToString()
    End If
Next

Open in new window

0
 

Author Comment

by:aarontham
ID: 24327404
it a quotation system. what if i have below scenario.

Honda        CRV
                   Civic

Honda       Civic
                 Accord
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24327593
If we change your Sql a bit, we can probably solve that issue:

    select * from brand,model where Brand.BrandID=Model.BrandID order by Brand.Brand

Now your list returned from the DB will be something like:
    Honda           CRV
    Honda           Civic
    Honda           Accord
    Toyota          Corrola
    Toyota          Titan

And the previous code I posted will not need to changed.
0
 

Author Comment

by:aarontham
ID: 24327694
i required it to display like below.

 Honda           CRV
                      Civic
                      Accord
 Toyota          Corrola
                      Titan
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24328034
I understand. What I am saying is that the query will return data in a format similar to my last post. After you add the data to your DataGridView, it will still look like it does in my last post. This is where you run the code I originally posted to run through each row and hide the repeated Brands.
0
 

Author Comment

by:aarontham
ID: 24328169
i have below error.
Object reference not set to an instance of an object.

on below code
If DataGridView1.Rows(i).Cells(0).Value.ToString() = current Then
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24330306
Put the code inside the DataBindingComplete handler for the DataGridView:
Private Sub dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) Handles dataGridView1.DataBindingComplete
    Dim current As String = DataGridView1.Rows(0).Cells(0).Value
 
    For i As Integer = 1 To Me.DataGridView1.Rows.Count - 1   ' change DataGridView1 to the name of your DG
        If row(i).Cells(0).Value.ToString() = current Then
            row(i).Cells(0).Value = String.Empty
        Else
            current = row(i).Cells(0).Value.ToString()
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:aarontham
ID: 24332828
i got same error.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 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