Prikazi cijelu temu 26.02.2020 08:31
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Lokacija:-


Predmet:svaki treći red iz datagrid-a
Da li postoji bolje rešenje za čitanje svakog trećeg reda iz datagrida? Kratak opis procedure, iz listview-a (podaci idu jedan posle drugog) prebacim podatke u datagrid1, podaci idu jedan ispod drugod (1 kolona više redova), iz njega prebacujem podatke u datagrid2 koji ima 3 kolone i veše redova (od_datuma, do_datuma, br_dana).

evo i koda:
*********************************************
Dim SourceDan As String = New Net.WebClient().DownloadString("https://www.nbs.rs/...11172934")

Dim recentSource As String = GetTagContents(SourceDan, "<table width=""100%"" border=""0"">", "</table>")(0)
Dim broj_dana_blokade As Integer

DataGridView1.ColumnCount = 2
DataGridView1.Columns(0).Name = "RB"
DataGridView1.Columns(0).Width = 40
DataGridView1.Columns(1).Name = "OD"
DataGridView1.Columns(1).Width = 100

DataGridView2.ColumnCount = 3
DataGridView2.Columns(0).Name = "OD"
DataGridView2.Columns(0).Width = 100
DataGridView2.Columns(1).Name = "DO"
DataGridView2.Columns(1).Width = 100
DataGridView2.Columns(2).Name = "DANI"
DataGridView2.Columns(2).Width = 100

For Each title As String In GetTagContents(recentSource, "<td>", "</td>")

Dim value As String = Trim(title.Replace(" ", ""))
Dim length As Integer = Trim(value.Replace(" ", "")).Length

If Not title.Contains("http:") Then

Dim lvi As New ListViewItem
lvi.Text = Trim(title.Replace(" ", "")) & " " & length
ListView1.Items.Add(lvi)

Dim j As Integer = 0

DataGridView1.Rows.Add(j + DataGridView1.RowCount, Trim(title.Replace(" ", "")))

End If

Next

Dim broj = 1

For Each red As DataGridViewRow In DataGridView1.Rows
Dim rednibroj As Integer = DataGridView2.Rows.Count - 1

If broj = 1 Then

Dim length As Integer = Trim(red.Cells(1).Value.Replace(" ", "")).Length
If length > 3 Then
DataGridView2.Rows.Add(Trim(red.Cells(1).Value).Replace(" ", ""))

broj = 2

ElseIf length > 1 And length < 4 Then

broj_dana_blokade = Trim(DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(1).Value.Replace(" ", ""))

TextBox1.Text = broj_dana_blokade.ToString
End If

ElseIf broj = 2 Then

DataGridView2.Rows(rednibroj).Cells(1).Value = Trim(DataGridView1.Rows(rednibroj * 3 + 1).Cells(1).Value.Replace(" ", ""))

broj = 3

ElseIf broj = 3 Then
DataGridView2.Rows(rednibroj).Cells(2).Value = Trim(DataGridView1.Rows(rednibroj * 3 + 2).Cells(1).Value.Replace(" ", ""))

broj = 1
End If

Next