Data Not in First row Datagridview

  • Thread starter Thread starter mipakteh
  • Start date Start date
M

mipakteh

Guest
Hi All,

What I want Data_1 in column1 show from Row 1 to the end and Data_2 in column2 show from Row 1 to the end.

somebody help me.

file text =22

0 ,2 ,
3 ,8 ,
4 ,6 ,
1 ,5 ,
0 ,5 ,
0 ,5 ,
1 ,2 ,
5 ,9 ,
2 ,5 ,
0 ,4 ,
0 ,9 ,
3 ,5 ,
7 ,9 ,
6 ,7 ,
0 ,4 ,
0 ,5 ,

Option Strict On
Option Explicit On
Public Class Form1
Dim path As String = "C:\Users\60129\Documents\Test_33.txt"
Dim AB As New List(Of String)
Dim Toc As New List(Of String)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

AB.AddRange(IO.File.ReadAllLines("C:\Users\60129\Documents\Test_22.txt"))

For J As Integer = 0 To AB.Count - 1
Dim entry As String = AB(J)
entry = entry.TrimEnd(CChar(","))
entry = entry.Replace(vbCrLf, ",")
entry = entry.Replace(" ", "")
entry = entry.Replace(",", "")
Toc.Add(entry)
Next

With DataGridView1
.Columns.Add("Column1", "Data_1")
.Columns.Add("Column2", "Data_2")
.Columns.Add("Column3", "Result")
.RowHeadersVisible = False
.Columns("Column1").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.AllowUserToAddRows = False

With .Columns("Column2")
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.DefaultCellStyle.WrapMode = DataGridViewTriState.True
.ReadOnly = True
End With
With .Columns("Column3")
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.DefaultCellStyle.WrapMode = DataGridViewTriState.True
.ReadOnly = True
End With

For Each line As String In Toc
.Rows.Add(line)
Next

For Each line As String In IO.File.ReadAllLines(path)
.Rows.Add(Nothing, line)
Next
.AutoResizeRows()
End With

End Sub

Private Sub DataGridView1_Resize(sender As Object, e As EventArgs) Handles DataGridView1.Resize
DataGridView1.AutoResizeRows()
End Sub

Function GetMat(ind As Integer, p As String) As Integer
Dim s As String = DataGridView1("Column2", ind).Value.ToString
Return System.Text.RegularExpressions.Regex.Matches(s, p).Count

End Function
Function GetMatches(ind As Integer) As String
Dim ret As String = Nothing
Dim p As String = DataGridView1("Column1", ind).Value.ToString
ret &= "Occurances (" & p & ") = " & GetMat(ind, p) & vbCrLf
ret &= "Occurances (" & RevString(p) & ") = " & GetMat(ind, RevString(p))
Return ret
End Function
Function RevString(s As String) As String
Dim pp() As Char = s.ToCharArray
Array.Reverse(pp)
Return New String(pp)
End Function
Private Sub DataGridView1_CellValidated(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValidated

If DataGridView1("Column1", DataGridView1.SelectedRows(0).Index).Value Is Nothing Then Exit Sub

DataGridView1("Column3", DataGridView1.SelectedRows(0).Index).Value = GetMatches(DataGridView1.SelectedRows(0).Index)
End Sub
End Class




Thank.

Continue reading...
 
Back
Top