Dataview

  • Thread starter Thread starter Fadoyo
  • Start date Start date
F

Fadoyo

Hi all, please, I would like to ask something:

I do have a dataview(dv1) with several Identifiers, then I want to creat a
new dataview(dv2) which row filter is any Identifier contained into the
other dataview ( dv1).

Thank you very much
Fadoyo Orithsuma.
 
Hi,

It would probably be something like this if I got you right:

Dim filter As New StringBuilder

Dim rowView As DataRowView
ForEach rowView in dataView1
If filter.Length > 0 Then
filter.Append(" OR ")
End If

filter.AppendFormat("Identifier={0}",
rowView("IdentifierColumn").ToString())
Next

dataView2.RowFilter = filter.ToString()
 
Hi, thank you,

Fadoyo
Dmitriy Lapshin said:
Hi,

It would probably be something like this if I got you right:

Dim filter As New StringBuilder

Dim rowView As DataRowView
ForEach rowView in dataView1
If filter.Length > 0 Then
filter.Append(" OR ")
End If

filter.AppendFormat("Identifier={0}",
rowView("IdentifierColumn").ToString())
Next

dataView2.RowFilter = filter.ToString()

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Fadoyo said:
Hi all, please, I would like to ask something:

I do have a dataview(dv1) with several Identifiers, then I want to creat a
new dataview(dv2) which row filter is any Identifier contained into the
other dataview ( dv1).

Thank you very much
Fadoyo Orithsuma.
 
Fadoyo,
Alternatively you could use the "In" operator, instead of the OR operator.

Something like (variation of Dmitriy's sample):

Dim filter As New StringBuilder ("Identifier In (")

Dim needDelim As Boolean = false

Dim rowView As DataRowView
For Each rowView in dataView1
If needDelim Then
filter.Append(","c)
End If

filter.Append(rowView("IdentifierColumn"))
needDelim = True
Next
filter.Append(")"c)

dataView2.RowFilter = filter.ToString()

I tend to prefer the "In" operator over a list of "Or" operators, as IMHO
the In operator is "easier" to follow. Otherwise they both do the same
thing!

Hope this helps
Jay

Fadoyo said:
Hi, thank you,

Fadoyo
Dmitriy Lapshin said:
Hi,

It would probably be something like this if I got you right:

Dim filter As New StringBuilder

Dim rowView As DataRowView
ForEach rowView in dataView1
If filter.Length > 0 Then
filter.Append(" OR ")
End If

filter.AppendFormat("Identifier={0}",
rowView("IdentifierColumn").ToString())
Next

dataView2.RowFilter = filter.ToString()

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Fadoyo said:
Hi all, please, I would like to ask something:

I do have a dataview(dv1) with several Identifiers, then I want to
creat
 
Back
Top