Centar za edukaciju-BiH



#1 26.02.2020 07:31
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


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
↑  ↓

#2 26.02.2020 10:26
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,611


Predmet:Re: svaki treći red iz datagrid-a
PreuzmiIzvorni kôd (Visual Basic):
  1. For Each red As DataGridViewRow In DataGridView1.Rows
  2. Dim rednibroj As Integer = DataGridView2.Rows.Count - 1
  3.  
  4. If broj = 1 Then
  5.  
  6. Dim length As Integer = Trim(red.Cells(1).Value.Replace(" ", "")).Length
  7. If length > 3 Then
  8. DataGridView2.Rows.Add(Trim(red.Cells(1).Value).Replace(" ", ""))
  9.  
  10. broj = 2
  11.  
  12. ElseIf length > 1 And length < 4 Then
  13.  
  14. broj_dana_blokade = Trim(DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(1).Value.Replace(" ", ""))
  15.  
  16. TextBox1.Text = broj_dana_blokade.ToString
  17. End If
  18.  
  19. ElseIf broj = 2 Then
  20.  
  21. DataGridView2.Rows(rednibroj).Cells(1).Value = Trim(DataGridView1.Rows(rednibroj * 3 + 1).Cells(1).Value.Replace(" ", ""))
  22.  
  23. broj = 3
  24.  
  25. ElseIf broj = 3 Then
  26. DataGridView2.Rows(rednibroj).Cells(2).Value = Trim(DataGridView1.Rows(rednibroj * 3 + 2).Cells(1).Value.Replace(" ", ""))
  27.  
  28. broj = 1
  29. End If
  30.  
  31. Next

Jeli to ova petlja?
Ne vidim ovdje kako povecavas variablu koja se zove broj.
Sa ovim broj bi mogao rijesiti da citas svaki treci ali ga moras povecavati za 3.
Prco reci jel ovo ta petlja i sto ce ti ovi if za broj.
Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#3 26.02.2020 10:43
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


Predmet:Re: svaki treći red iz datagrid-a
Da, to je ta petlja. Jedino sam ovako uspeo da dobijem reÅ¡enje za svaki treći red. Probao sam i sa For petljom step 3 (kod dole) ali nikako nisam uspeo da dodelim vrednosti u koloni 2 i 3 jer mi index ide preko poslednjeg rednog broja. Evo i slike (gore levo, lista, dole levo moje reÅ¡enje, dole desno pokuÅ¡aj sa for petljom i step 3

Dim rednibroj As Integer = DataGridView1.Rows.Count - 1
For i As Integer = 0 To rednibroj Step 3

od_datuma = DataGridView1.Rows(i).Cells(1).Value
' do_datuma = DataGridView1.Rows(i + 1).Cells(1).ToString
' broj_dana = DataGridView1.Rows(i + 2).Cells(1).Value

DataGridView3.Rows.Add(od_datuma)
Next

Slicice prilozenih slika:
resenje.png
Tip datoteke:Informacije o tipu datoteke za:png png
Preuzimanja:231
Velicina datoteke:45.54 KB
Velicina slike: 1423 x 767 Pikseli

↑  ↓

#4 26.02.2020 13:19
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,611


Predmet:Re: svaki treći red iz datagrid-a
PreuzmiIzvorni kôd (Visual Basic):
  1. Dim x As Integer
  2. For Each red As DataGridViewRow In DataGridView1.Rows
  3. 'Dim rednibroj As Integer = DataGridView2.Rows.Count - 1
  4. x = x + 1
  5. If x Mod 3 = 0 Then
  6. MsgBox (oDataGridView1.Rows(i - 1).Cells(1).Value)
  7. End If
  8.  
  9. Next
neznam koji red niti koju kolonu citas.
Nisi se izjasnio napr. re 1-4 itd ili red 3 6
u ov 3 grida imas razlicit broj kolona pa neznam koju kolonu citas
Ako se ne snadjes pisi ponovo
Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

Stranice (1):1


Sva vremena su GMT +01:00. Trenutno vrijeme: 3: 26 pm.