13 Replies - 2855 Views - Last Post: 06 July 2012 - 09:52 AM Rate Topic: -----

#1 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

listview into datagridview

Posted 23 June 2012 - 07:27 AM

hello guys..here is the problem..i have datagridview,listview, and database..how to retrieve the data from database into datagridview by using item in listview?
Is This A Good Question/Topic? 0
  • +

Replies To: listview into datagridview

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 23 June 2012 - 11:36 AM

Are you talking about filtering by item in listview? Please be more detailed in your questions and show what you have tried. Forum rules.
Was This Post Helpful? 0
  • +
  • -

#3 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 23 June 2012 - 07:08 PM

yes..it like filtering the item..i have this code that display 4 number in every line in listview..
Public Sub UPdateTextBox()
        If comport.IsOpen Then
            Dim bytes As Integer = comport.BytesToRead
            Dim buffer(bytes) As Byte
            Dim tagid As String
            'Dim i As Integer
            '\\ to read data from read buffer
            comport.Read(buffer, 0, bytes)
            If buffer.Length > 1 Then
                tagid = ByteArrayToHexString(buffer)
                'If txtSearch.TextLength = 16 Then
                txtSearch.Text = tagid

                Dim tags As String = tagid.ToString
                tags = tags.Substring(0, 4)
               ' Dim test As String = "qweqwe1212adfaf2433adfa1133"
                Dim allrfids As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(tagid, "\d{4}(01)*")
                For Each rfid As System.Text.RegularExpressions.Match In allrfids
                    tags = rfid.ToString
                    tags = tags.Substring(0, 4)
                    TextBox3.Text = tags
                    'MsgBox("TAG: " & tags)
                    ListView1.Items.Add(tags)


what i want is to used the item in this listview to retrieve data in database and insert it into datagridview..
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 23 June 2012 - 07:30 PM

If you fill a dataset with the tables you can make a sub query using LINQ or lambda expression on the DataTable using the item in the listview that is selected and set the DGV.DataSource = query.
Was This Post Helpful? 0
  • +
  • -

#5 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 24 June 2012 - 04:23 AM

im new in vb.net..how to use that query..
i have this code for datagridview..

 Dim dbcom As OleDbCommand = New OleDbCommand("SELECT * FROM Tracking where RFID = '"  tags  "'", con1)  
                    If TrackingTableAdapter.Connection.State = ConnectionState.Closed Then
                        TrackingTableAdapter.Connection.Open()
                    End If

                    Dim dbcom As OleDbCommand = New OleDbCommand("SELECT * FROM Tracking where RFID = '" & tags & "'", TrackingTableAdapter.Connection)
                    
                    Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(dbcom)
                    Dim myDataset As DataSet = New DataSet()
                    myDA.Fill(myDataset, "tracking")
                    Dgv1.DataSource = myDataset.Tables("tracking").DefaultView



the problem is only the last item in the listview that able to display the data from database in this datagridview.
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 24 June 2012 - 06:07 AM

Dim query = From dr As DataRow In myDataset.Tables("tracking").Rows Where dr(<column name>) = "some value to filter on"

Dgv1.DataSource = query


query is an IEnumerable(Of DataRow) object, basically an array of datarows which can be viewed in your GDV.

This post has been edited by _HAWK_: 24 June 2012 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#7 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 24 June 2012 - 07:27 AM

i have modified the code
Dim dbcom As OleDbCommand = New OleDbCommand("SELECT * FROM Tracking where RFID = '" & tags & "'", con1)    
                    If TrackingTableAdapter.Connection.State = ConnectionState.Closed Then
                        TrackingTableAdapter.Connection.Open()
                    End If

                    'Dim dbcom As OleDbCommand = New OleDbCommand("SELECT * FROM Tracking where RFID = '" & tags & "'", TrackingTableAdapter.Connection)
                   

                    Dim query = From dr As DataRow In myDataset.Tables.row Where dr(<id></id>) = "tags" 'error in this line..row is not a member of systemdata.datatablecollection
                    Dgv1.DataSource = query
                    Dim myDA As OleDbDataAdapter = New OleDbDataAdapter
                    Dim myDataset As DataSet = New DataSet()
                    myDA.Fill(myDataset, "tracking")
                    Dgv1.DataSource = myDataset.Tables("tracking").DefaultView



let me rephrase my problem..i just want to display data from database into datagridview when there is a match item between list in listview with data in database..

my list in listview will display like this:
1234
5432
5435

in my database i have a field of
rfid nama page
1234 adam 1
7657 johnson 2

so, what i want is every match in listview with database i.e 1234, the data of 'nama' and 'page' will be display in datagridview.. which is : adam 1
Was This Post Helpful? 0
  • +
  • -

#8 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 24 June 2012 - 08:17 AM

You can't query before you fill the datatable.
Was This Post Helpful? 0
  • +
  • -

#9 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 24 June 2012 - 08:29 AM

what do you mean by fill the datatable..im new in vb..hope you can help..thanks in advance
Was This Post Helpful? 0
  • +
  • -

#10 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 24 June 2012 - 10:26 AM

Did you notice the Fill method on your DataAdapter that fills the table? And you are assigning the entire query from the database to the DVG not the custom one. so you have 2 choices either modify the orginal sql query with the parameter you want to filter on or do like I suggested if you want both.
Was This Post Helpful? -1
  • +
  • -

#11 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 04 July 2012 - 08:41 PM

View Post_HAWK_, on 24 June 2012 - 06:07 AM, said:

Dim query = From dr As DataRow In myDataset.Tables("tracking").Rows Where dr(<column name>) = "some value to filter on"

Dgv1.DataSource = query


query is an IEnumerable(Of DataRow) object, basically an array of datarows which can be viewed in your GDV.


where to put those code?
Was This Post Helpful? 0
  • +
  • -

#12 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 04 July 2012 - 10:17 PM

What would make sense, after loading the dataset, clicking a button?
Was This Post Helpful? 0
  • +
  • -

#13 hrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 12

Re: listview into datagridview

Posted 06 July 2012 - 03:49 AM

if i want after clicking a button where to put the code..thanks in advance
Was This Post Helpful? 0
  • +
  • -

#14 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: listview into datagridview

Posted 06 July 2012 - 09:52 AM

Do you know how to make an event for the button click? In the designer double click on the button and it will build it for you and then you put the code in here.

Don't take this wrong, but if you are not familiar with events and other simple UI controls you should work on the basics before you engage in advanced data models and queries. You must have a firm grasp or you will continue to struggle rather than enjoy your projects. Search MSDN for the controls you use - this will give you the ability to explore all the methods, properties and events along with documentation and examples. All of us here are committed to helping when you show you have made an effort.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1