Hi All,

I have two dimentional array, i want to filter the records in array
is there any way to do it?

Recommended Answers

All 5 Replies

Hi,

What do you have so far?

Not knowing exactly what you're trying to achieve. May be you want to use LINQ.

Dim a(,) As Integer = {{11, 22}, {24, 34}, {44, 55}}

  Dim result = From n In a Where n > 20 Select n

  For Each p In result
       Console.WriteLine(p)
  Next

Hi,
Im using one third party grid which provides me a mthod called getarray to get the collection of the columns into two dimentional array.
fisrt column is checkbox, My need is If checkbox is checked i want to check wheater user entered data in another column or not.
Now im able to get all the rows and two colmns into array. i dont want to loop through all the records.
Hope i made it clear.. if not plz ask..

Thanks

What do you think of something like this:

Class Program
	Private Shared Sub Main(args As String())
		'example of 4 rows and 2 columns:
		'particular bracket: 
		'1st number is value of checkBox (1 is Checked, 0 is not checked)
		'2nd number is value of text existance (1 text exist, 0 text does not exist)

		Dim array As Integer(,) = New Integer(3, 1) {{1, 0}, {0, 0}, {1, 1}, {0, 1}}

		Dim list As New List(Of MyData)()
		For i As Integer = 0 To array.GetLength(0) - 1
			Dim data As New MyData()
			For j As Integer = 0 To array.GetLength(1) - 1
				data.Column1 = array(i, j)
				data.Column2 = array(i, j + 1)
				list.Add(data)
				Exit For
			Next
		Next

		For Each data As MyData In list
			Console.WriteLine(data)
		Next
		Console.ReadLine()
		'
'            for (int i = 0; i < array.GetLength(0); i++)
'            {
'                for (int j = 0; j < array.GetLength(1); j++)
'                {
'                    bool bChecked = array[i, j] == 1 ? true : false;
'                    if (bChecked)
'                    {
'                        bool bHasText = array[i, j + 1] == 1 ? true : false;
'                    }
'                    break;
'                }
'            }

	End Sub


End Class
Class MyData
	Public Property Column1() As Integer
		Get
			Return m_Column1
		End Get
		Set
			m_Column1 = Value
		End Set
	End Property
	Private m_Column1 As Integer
	Public Property Column2() As Integer
		Get
			Return m_Column2
		End Get
		Set
			m_Column2 = Value
		End Set
	End Property
	Private m_Column2 As Integer

	Public Overrides Function ToString() As String
		Return String.Format("CheckBox {0}, text {1}.", (If(Column1 = 1, "IS CHECKED", "NOT CHECKED")), (If(Column2 = 1, "EXIST", "DO NOT EXIST")))
	End Function
End Class

Hi Mitja,

Yes this may works.. but as the list will be huge i would like to avoid looping.
LINQ will be best idea.. let me try..
Thanks for ur reply..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.