1 Replies - 1681 Views - Last Post: 12 February 2010 - 02:15 AM Rate Topic: -----

#1 EndLessMind   User is offline

  • Android Expert
  • member icon

Reputation: 273
  • View blog
  • Posts: 1,252
  • Joined: 13-March 09

For each row in my search result.

Posted 11 February 2010 - 03:45 PM

Hi.
I have a Search function on my database.
It count´s how may search result you get but now i want to load one column from each search result ( for each row in a DataTable ) into a "ToolStripDropDownButton.dropdownitems"

How do i do that?

Here is the code i got so far
 pg1.Value = 0
        'Try

        Dim sqlsearch As String
        sqlsearch = "SELECT * FROM medlem WHERE Medlemsnummer LIKE '%" & ToolStripTextBox1.Text & "%'"
        Dim adapter As New OleDbDataAdapter(sqlsearch, con)
        dt = New DataTable("medlem")
        pg1.Value = 20
        adapter.Fill(dt)
        If dt.Rows.Count > 0 Then
            maxrows1 = dt.Rows.Count
            inc1 = -1
            inc1 = 0
            NavigateRecords1()
            pg1.Value = 70
            ToolStripLabel1.Text = "Antal sökreslultat: " & maxrows1
            If maxrows1 > 1 Then
                ToolStripDropDownButton2.Visible = True
                
                'ToolStripDropDownButton2.DropDownItems.Add(DataReader("Förnamn").ToString.ToUpper.Trim)


            ElseIf maxrows1 = 1 Then
                ToolStripDropDownButton2.Visible = False
            End If
            pg1.Value = 100
        Else
            MsgBox("Inga sökresultat")
            'Catch ex As Exception
            'MsgBox(ex.Message)
            'End Try
        End If
        pg1.Value = 0


thanks in advance :)

This post has been edited by EndLessMind: 11 February 2010 - 05:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: For each row in my search result.

#2 EndLessMind   User is offline

  • Android Expert
  • member icon

Reputation: 273
  • View blog
  • Posts: 1,252
  • Joined: 13-March 09

Re: For each row in my search result.

Posted 12 February 2010 - 02:15 AM

i got it to work :)

with a loop like this

   pg1.Value = 0
        'Try
        Dim ic As Integer = 0
        Dim sqlsearch As String
        sqlsearch = "SELECT * FROM medlem WHERE Medlemsnummer LIKE '%" & ToolStripTextBox1.Text & "%'"
        Dim adapter As New OleDbDataAdapter(sqlsearch, con)
        dt = New DataTable("medlem")
        pg1.Value = 20
        adapter.Fill(dt)
        If dt.Rows.Count > 0 Then
            maxrows1 = dt.Rows.Count
            inc1 = -1
            inc1 = 0
            NavigateRecords1()
            pg1.Value = 70
            ToolStripLabel1.Text = "Antal sökreslultat: " & maxrows1
            If maxrows1 > 1 Then
                ToolStripDropDownButton2.Visible = True
                'If DataReader.HasRows Then
                Do Until ic = maxrows1
                    ToolStripDropDownButton2.DropDownItems.Add(dt.Rows(ic).Item(0) & " " & dt.Rows(ic).Item(1))
                    ic += 1
                Loop
                'End If
                'ToolStripDropDownButton2.DropDownItems.Add(

            ElseIf maxrows1 = 1 Then
                ToolStripDropDownButton2.Visible = False
            End If
            pg1.Value = 100
        Else
            MsgBox("Inga sökresultat")
            'Catch ex As Exception
            'MsgBox(ex.Message)
            'End Try
        End If
        pg1.Value = 0



but i cant find how to add "tag" to each new item.

because if i can get it to work. then i can use this one
Public Sub HandleSearchMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
         Select e.Button
            Case Windows.Forms.MouseButtons.Left
                Dim inc2 As Integer

                tdd = sender
                inc2 = tdd.Tag

                txtfm.Text = dt.Rows(inc2).Item(0)
                txtem.Text = dt.Rows(inc2).Item(1)
                txtga.Text = dt.Rows(inc2).Item(2)
                txtpn.Text = dt.Rows(inc2).Item(3)
                txts.Text = dt.Rows(inc2).Item(4)
                txttm.Text = dt.Rows(inc2).Item(5)
                txtth.Text = dt.Rows(inc2).Item(6)
                txtep.Text = dt.Rows(inc2).Item(26)
                txtp.Text = dt.Rows(inc2).Item(25)
                txtma.Text = dt.Rows(inc2).Item(7)
                txta1.Text = dt.Rows(inc2).Item(8)
                txtpc.Text = dt.Rows(inc2).Item(9)
                txtgf.Text = dt.Rows(inc2).Item(10)
                cmba.Text = dt.Rows(inc2).Item(11)
                txthd.Text = dt.Rows(inc2).Item(12)
                cmbop.Text = dt.Rows(inc2).Item(14)
                cmbdl.Text = dt.Rows(inc2).Item(15)
                cmbmt.Text = dt.Rows(inc2).Item(13)
                txtn.Text = dt.Rows(inc2).Item(16)
                txttmf.Text = dt.Rows(inc2).Item(17)
                txtthf.Text = dt.Rows(inc2).Item(18)
                txtgaf.Text = dt.Rows(inc2).Item(19)
                txtpnf.Text = dt.Rows(inc2).Item(20)
                txtsf.Text = dt.Rows(inc2).Item(21)
                txtsb.Text = dt.Rows(inc2).Item(23)
                txta2.Text = dt.Rows(inc2).Item(22)
                txtmr.Text = dt.Rows(inc2).Item(24)

        End Select

    End Sub


to navigate to that record when i press a search result in the dropdown button.

i tried like this this the loop

Dim tdd As New ToolStripLabel
 Do Until ic = maxrows1

                    ToolStripDropDownButton2.DropDownItems.Add(tdd)
                    tdd.Text = dt.Rows(ic).Item(0) & " " & dt.Rows(ic).Item(1)
                    tdd.Tag = ic
                    ic += 1
                Loop



but then it just add´s on of the search result to the dropdownbutton.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1