Results 1 to 6 of 6

Thread: Confused on how datagridviews work. :(

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Confused on how datagridviews work. :(

    I want to make a database of all the xbox live arcade arcade games on the xbox live marketplace, I need to parse an xml file and add the needed data from the xml node into a datagridview.

    Here is the xml file i need to use to grab links and other data about the game:
    http://updates.xboxmodder.com/updates.xml

    Being the noob I am it took me about 6 hours to figure out how xml works and to write some code for what i need to do.

    Here is what i came up with:

    Code:
    'for grabbing the name of the update
    Public Sub updatename()
             Dim xmldoc As New XmlDataDocument()
    
            Dim xmlnode As XmlNodeList
    
            Dim i As Integer
    
            Dim str As String
    
    
            xmldoc.Load("http://updates.xboxmodder.com/updates.xml")
    
            xmlnode = xmldoc.GetElementsByTagName("file")
    
            For i = 0 To xmlnode.Count - 1
    
                xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
    
                str = xmlnode(i).ChildNodes.Item(1).InnerText.Trim()
    
                DataGridView1.Rows.Add(str)
    
            Next
    
    end sub

    That code works fine.

    Now when i add another column to the datagridview called "update size" i want to know how to add the grabbed data from another sub i made to the new column.
    What would the code be for adding the strings for the new sub into the seconds column? the first was, DataGridView1.Rows.Add(str)" . So what would the second be ?

    Also another question i have is how do i put an image in an imagecolumn by a web link, not a local picture.

    Please go easy on me, i'm still learning and havent even started my programming classes yet , just trying to prepare for it and learn by making programs for my needs.

    Thanks.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Confused on how datagridviews work. :(

    can you post the 2nd sub?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Confused on how datagridviews work. :(

    here's a simple example, but you'll probably need to tie in column2 with the values in column1:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     DataGridView1.Columns.Add("Column2", "Column2")
    3.     For x As Integer = 0 To DataGridView1.Rows.Count - 1
    4.         DataGridView1.Rows(x).Cells(1).Value = x
    5.     Next
    6. End Sub

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Confused on how datagridviews work. :(

    Quote Originally Posted by JJMPSP View Post
    Also another question i have is how do i put an image in an imagecolumn by a web link, not a local picture.
    try this:

    vb.net Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.     Dim t As New Threading.Thread(AddressOf addImages)
    3.     t.Start(DataGridView1)
    4. End Sub
    5.  
    6. Private Delegate Sub addImagesCallback(ByVal dgv As Object)
    7.  
    8. Private Sub addImages(ByVal dgv As Object)
    9.     If DirectCast(dgv, DataGridView).InvokeRequired Then
    10.         DirectCast(dgv, DataGridView).Invoke(New addImagesCallback(AddressOf addImages), dgv)
    11.     Else
    12.         Dim MyWebClient As New System.Net.WebClient
    13.         DirectCast(dgv, DataGridView).Columns.Add(New DataGridViewImageColumn)
    14.         For x As Integer = 0 To DirectCast(dgv, DataGridView).Rows.Count - 1
    15.             Dim ImageInBytes() As Byte = MyWebClient.DownloadData("url")
    16.             Application.DoEvents()
    17.             DirectCast(dgv, DataGridView).Rows(x).Cells(DirectCast(dgv, DataGridView).Columns.Count - 1).Value = Image.FromStream(New IO.MemoryStream(ImageInBytes))
    18.         Next
    19.     End If
    20. End Sub
    Last edited by .paul.; Jun 16th, 2010 at 03:11 PM.

  5. #5
    Lively Member
    Join Date
    May 2010
    Posts
    103

    Re: Confused on how datagridviews work. :(

    If you already have the second column made, then you can do this;


    vb Code:
    1. Dim dgvR as DataGridViewRow
    2. Dim x as Integer = 0
    3.  
    4. For Each dgvR in DataGridView1.Rows
    5.    dgvR.Cells.Item(1).Value = xmlnode(x).ChildNodes.Item(1).InnerText.Trim()
    6.    x += 1
    7. Next

    Change the 1 in "dgvR.Cells.Item(1).Value" to whatever column you want filled in each row.

    xmlNode = list of data to loop through and append.

    This is just one of many ways..

    Personally, I would fill both columns at the same time instead of one column at a time.
    Last edited by MotoX646; Jun 16th, 2010 at 03:57 PM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Re: Confused on how datagridviews work. :(

    Hi guys, thanks for your replies
    I have gave you both some rep for your time.
    However after another several hours of trying to get this to work i eventually gave up as the code was a bit too advanced for me and i kept getting random errors of which i had no clue how to fix

    In the end i used this code to make a dataset out of the xml nodes.

    Code:
    Public Sub everythingelse()
    
            Dim xmlDatadoc1 As XmlDataDocument = New XmlDataDocument
            xmlDatadoc1.DataSet.ReadXml("http://updates.xboxmodder.com/updates.xml")
            Dim ds1 As DataSet = New DataSet("Title Updates Database")
            ds1 = xmlDatadoc1.DataSet
            DataGridView1.DataSource = ds1.DefaultViewManager
            DataGridView1.DataMember = "file"
            DataGridView1.ReadOnly = True
    works like a charm !

    I am marking this as solved as it may help others and i seem to have solved my own problem. Again thanks to the 2 users that replied !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width