Написать приложение "Школьный журнал" - Visual Basic .NET
Формулировка задачи:
как можно составить журнал оценок на vb.net DataGridview Помогите Пожалуйста
Решение задачи: «Написать приложение "Школьный журнал"»
textual
Листинг программы
Imports System.IO Imports System.Text Public Class Form3 Private txtName As String Private delim As String Private classReg(,) As String Private title() As String Private nn, mm As Integer Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load txtName = Path.Combine(Application.StartupPath, "classRegister2015.csv") delim = ";" If File.Exists(txtName) Then readData() setDGV() End If End Sub Private Sub readData() Try Dim rr() As String = File.ReadAllLines(txtName, Encoding.Default) nn = rr.Length title = rr(nn - 1).Split(delim) mm = title.Length nn -= 1 ReDim Preserve rr(nn - 1) ReDim classReg(nn - 1, mm - 1) For i = 0 To nn - 1 Dim cc() As String = rr(i).Split(delim) For j = 0 To mm - 1 classReg(i, j) = cc(j) Next Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub setDGV() Try With DataGridView1 .ColumnCount = mm For j = 0 To mm - 1 .Columns(j).HeaderText = title(j) Next For i = 0 To nn - 1 .Rows.Add(New DataGridViewRow()) For j = 0 To mm - 1 .Rows(i).Cells(j).Value = classReg(i, j) Next Next .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells .Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.None .Columns(0).Width = 150 .Columns(0).Frozen = True .Columns(0).DividerWidth = 3 .EnableHeadersVisualStyles = False .ColumnHeadersDefaultCellStyle.BackColor = Color.LightYellow .ColumnHeadersDefaultCellStyle.Font = New Font(.Font.FontFamily, .Font.Size, FontStyle.Bold) .ColumnHeadersDefaultCellStyle.Padding = New Padding(5, 5, 0, 5) .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single .Columns(0).DefaultCellStyle.BackColor = Color.LightYellow .TopLeftHeaderCell.Value = "8A" End With Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'New Date With DataGridView1 .Columns.Add("col" & nn.ToString, Format(Now, "d.MM")) .FirstDisplayedCell = .Rows(0).Cells(.Columns.Count - 1) End With End Sub Private Sub DataGridView1_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting 'двойки отмечаем красным If IsNumeric(e.Value) Then If CInt(e.Value) < 3 Then e.CellStyle.ForeColor = Color.Red End If End If End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click 'Save With DataGridView1 nn = .Rows.Count - 1 mm = .Columns.Count ReDim classReg(nn, mm - 1) For i = 0 To nn - 1 For j = 0 To mm - 1 classReg(i, j) = .Rows(i).Cells(j).Value Next Next For j = 0 To mm - 1 classReg(nn, j) = .Columns(j).HeaderText Next End With Dim s As String = "" Dim ss(nn) As String For i = 0 To nn s = "" For j = 0 To mm - 1 s &= classReg(i, j) & delim Next ss(i) = s.Substring(0, s.Length - delim.Length) Next File.WriteAllLines(txtName, ss, Encoding.Default) End Sub End Class
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д