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.
Re: Confused on how datagridviews work. :(
can you post the 2nd sub?
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.Columns.Add("Column2", "Column2")
For x As Integer = 0 To DataGridView1.Rows.Count - 1
DataGridView1.Rows(x).Cells(1).Value = x
Next
End Sub
Re: Confused on how datagridviews work. :(
Quote:
Originally Posted by
JJMPSP
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:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim t As New Threading.Thread(AddressOf addImages)
t.Start(DataGridView1)
End Sub
Private Delegate Sub addImagesCallback(ByVal dgv As Object)
Private Sub addImages(ByVal dgv As Object)
If DirectCast(dgv, DataGridView).InvokeRequired Then
DirectCast(dgv, DataGridView).Invoke(New addImagesCallback(AddressOf addImages), dgv)
Else
Dim MyWebClient As New System.Net.WebClient
DirectCast(dgv, DataGridView).Columns.Add(New DataGridViewImageColumn)
For x As Integer = 0 To DirectCast(dgv, DataGridView).Rows.Count - 1
Dim ImageInBytes() As Byte = MyWebClient.DownloadData("url")
Application.DoEvents()
DirectCast(dgv, DataGridView).Rows(x).Cells(DirectCast(dgv, DataGridView).Columns.Count - 1).Value = Image.FromStream(New IO.MemoryStream(ImageInBytes))
Next
End If
End Sub
Re: Confused on how datagridviews work. :(
If you already have the second column made, then you can do this;
vb Code:
Dim dgvR as DataGridViewRow
Dim x as Integer = 0
For Each dgvR in DataGridView1.Rows
dgvR.Cells.Item(1).Value = xmlnode(x).ChildNodes.Item(1).InnerText.Trim()
x += 1
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.
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 ! :D