hi,

I am having a prob in collection object...My prob is Server sends a data and i have to save the data in flexgrid.I am using this data as a key and for the reference i am saving flexgrid row number with key. If another data comes.i just want to refer the collection and if exists in collection , using the row number i want to replace in flexgrid. If its not exists then add in a new row of flexgrid... I am new to programming. so i dont know how to get the key and how to store row number with the key.. getting lot of confusion.. pls help me to solve this..

Recommended Answers

All 3 Replies

In this simplistic example, the "Info 1" (2-3) is what you are searching for while the "1"/"2"/"3" could be considered as your row numbers.

Dim C As New Collection, FoundItem As Boolean, ForLoopCounter As Integer
C.Add "Info 1", "1"
C.Add "Info 2", "2"
C.Add "Info 3", "3"

For ForLoopCounter = 1 To C.Count
  
  If C.Item(ForLoopCounter) = "Info 2" Then
    
    FoundItem = True
    Exit For
    
  End If
  
Next ForLoopCounter

So what you are saying is that you would search on the item and if found you would know which row it was in because of the loop counter.

Just remember to add them to the collection the say way you added them to the grid.

Then again, why can you not search the grid itself?

Good Luck

i can search in grid itself.. then wat is the need of storing in collection.. i am trying to store in collection with the row number i placed in grid.. if the same item comes again to collection. it will check with collection and get the row number.. then send the data to correct position and replace there.. this s simple way instead of checking grid..

Thanks,

****Pinkyguru****

start a new project for a test project. Add a MSFlexGrid and name it FG, add a command button, add the code, run, test,

Option Explicit

Dim NumberOfRows As Integer

Private Sub Form_Load()
FG.AddItem "1", 1
FG.AddItem "2", 2
FG.AddItem "3", 3
FG.AddItem "4", 4
FG.AddItem "5", 5

FG.Row = 0
FG.Col = 1
FG.Text = "Search Key"

FG.Row = 1
FG.Col = 1
FG.Text = "abc"

FG.Row = 2
FG.Text = "bcd"

FG.Row = 3
FG.Text = "asdf"

FG.Row = 4
FG.Text = "qwerty"

FG.Row = 5
FG.Text = "zxcv"

FG.Row = 0
FG.Col = 2
FG.Text = "Update Value"

FG.Row = 1
FG.Text = "Orig value"

FG.Row = 2
FG.Text = "Orig value"

FG.Row = 3
FG.Text = "Orig value"

FG.Row = 4
FG.Text = "Orig value"

FG.Row = 5
FG.Text = "Orig value"

NumberOfRows = 5

End Sub

Private Sub Command1_Click()

Dim ForLoopCounter As Integer, Found As Boolean, SearchValue As String

FG.Col = 1
SearchValue = "qwerty"

For ForLoopCounter = 1 To NumberOfRows
  FG.Row = ForLoopCounter
  If FG.Text = SearchValue Then
    FG.Col = 2
    FG.Text = "New value"
    Found = True
    Exit For
  End If
Next ForLoopCounter

If Found = False Then
  NumberOfRows = NumberOfRows + 1
  FG.AddItem CStr(NumberOfRows), NumberOfRows
  FG.Row = NumberOfRows
  FG.Col = 1
  FG.Text = SearchValue
  FG.Col = 2
  FG.Text = "Orig value"
End If

FG.Col = 1
SearchValue = "test"
Found = False

For ForLoopCounter = 1 To NumberOfRows
  FG.Row = ForLoopCounter
  If FG.Text = SearchValue Then
    FG.Col = 2
    FG.Text = SearchValue
    Found = True
    Exit For
  End If
Next ForLoopCounter

If Found = False Then
  NumberOfRows = NumberOfRows + 1
  FG.AddItem CStr(NumberOfRows), NumberOfRows
  FG.Row = NumberOfRows
  FG.Col = 1
  FG.Text = SearchValue
  FG.Col = 2
  FG.Text = "Orig value"
End If
End Sub

Good Luck

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.