DataGrid and DataSet information

  • Thread starter Thread starter Sébastien
  • Start date Start date
S

Sébastien

Hi,

I have 2 parents tables (example : Car and Road). That Car can use n
Roads and Road can be use by n Cars. In that case, I need a middle table
because it is a n-to-n relation. So we had a Link_Car_Road table with the
primary key of Road and Car as foreign key in Link_Car_Road.

So if I want to design a form to show the car informations with all the road
corresponding to that car, I need to use a DataGrid (I think, because it
seems impossible with a ListBox). I am able to show the car ifnromations
with the Link_Car_Road information, but I am unable to get the Road with my
DataGrid. To do it, I set the DataSource of my DataGrid to my DataSet and my
CalueMember to Car.Link_Car_Road_Relation. So when I select a new car
record, I get all the child rows of Link_Car_Road that correspond to that
car. IS there any way to get the Road information instead the middle table
informations when I select a new car row ?

Thank you for your help.
 
Sebastien:

I think binding to a DataView and adjusting the rowfilter is a decent way to
get there. Say the Road grid is bound to the row filter and you change car.
You can then reset the rowfilter of the Link_Car_Road table (which should
only have ostensibly one record if I understand the schema correctly. From
there, the .RowFilter for the Road View could be set to the value in
Link_Car_Road. Once the Rowfilter is set to the correct value, the correct
records will show in the Road grid immediately.
 
The Link_Car_Road table will have multiple record of the same car or Road.
Example :

I have Car 1, 2 and 3
I have Road 11, 12 and 13

My table could look like

1 11
2 11
1 13
1 12
3 11
2 13
3 13

So if I understand you solution, It will work inly with one record.

I think I could use the GetParentRows method, but I am not sure we can use
DataBinding with that.

Thank you for your help.
 
Ok, but the solution will still work. All you'll need to do is loop through
the filtererd rows on of the dataview and construct a RowFilter expression
based on multiple criteria:

So lets say that originally you wanted to set it so RowFilter = "Road_ID =
'1' assuming you go 1 as a filtered value. Instead, now you might have 5
different values. You could change it so RowFilter = "Road_ID IN ('1', '2',
'3', '4','5').

Here's a sample of a proc I wrote to walk through a DataTable and extract
duplicate values...from there, I build an IN Expression so I can set my
rowfilter to only show values that are duplicates.

Public Sub ShowOnlyDuplicates(ByVal Dups As ArrayList)

If Dups.Count = 0 Then

MessageBox.Show("There doesn't appear to be any duplicate records", "No
Duplicates Found", MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit Sub

End If

Dim sb As New System.Text.StringBuilder

sb.Append(FieldName & " IN( ")

For i As Integer = 0 To Dups.Count - 1

If i = 0 Then

sb.Append("'" & CType(Dups(i), String) & "'")

Else

sb.Append(", '" & CType(Dups(i), String) & "'")

End If

Next

sb.Append(")")

GridSource.RowFilter = sb.ToString

GridSource.Sort = "Excel_Job_Number"

End Sub



HTH,



Bill
 
Back
Top