aarontham
asked on
don't display copy vb.net 2008
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.BrandI D
it show below in Datagribview
Honda CRV
Honda Civic
Honda Accord
how to show like below in datagridview
Honda CRV
Civic
Accord
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.BrandI
it show below in Datagribview
Honda CRV
Honda Civic
Honda Accord
how to show like below in datagridview
Honda CRV
Civic
Accord
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
ASKER
it a quotation system. what if i have below scenario.
Honda CRV
Civic
Honda Civic
Accord
Honda CRV
Civic
Honda Civic
Accord
If we change your Sql a bit, we can probably solve that issue:
select * from brand,model where Brand.BrandID=Model.BrandI D 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.
select * from brand,model where Brand.BrandID=Model.BrandI
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.
ASKER
i required it to display like below.
Honda CRV
Civic
Accord
Toyota Corrola
Titan
Honda CRV
Civic
Accord
Toyota Corrola
Titan
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.
ASKER
i have below error.
Object reference not set to an instance of an object.
on below code
If DataGridView1.Rows(i).Cell s(0).Value .ToString( ) = current Then
Object reference not set to an instance of an object.
on below code
If DataGridView1.Rows(i).Cell
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i got same error.
Open in new window