-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogForm.cs
97 lines (86 loc) · 3.14 KB
/
LogForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LogViewer
{
public partial class LogForm : Form
{
private static DataGridViewCellStyle defaultStyle;
private CsvFile file;
public LogForm(CsvFile file)
{
this.file = file;
InitializeComponent();
}
private static DataGridViewCellStyle DefaultStyle
{
get
{
if (defaultStyle == null)
{
defaultStyle = new DataGridViewCellStyle();
defaultStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
defaultStyle.BackColor = System.Drawing.Color.White;
defaultStyle.SelectionBackColor = Color.Black;
defaultStyle.SelectionForeColor = Color.White;
}
return defaultStyle;
}
}
private void LogForm_Load(object sender, EventArgs e)
{
try
{
this.grid.RowHeadersWidth = 4;
foreach (string headerName in this.file.Headers)
{
DataGridViewColumn column = new DataGridViewColumn();
column.HeaderText = headerName;
column.CellTemplate = new DataGridViewTextBoxCell();
column.Width = 50;
this.grid.Columns.Add(column);
}
foreach (ReadOnlyList<string> row in this.file.Rows)
{
DataGridViewRow gridRow = new DataGridViewRow();
gridRow.HeaderCell.Value = row[0];
this.grid.Rows.Add(gridRow);
}
for (int rowIndex = 0; rowIndex < this.grid.Rows.Count; rowIndex++)
{
for (int columnIndex = 0; columnIndex < this.grid.Columns.Count; columnIndex++)
{
string value = this.file.Rows[rowIndex][columnIndex];
this.grid.Rows[rowIndex].Cells[columnIndex].Value = value;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Exception in Load");
}
}
private void LogForm_Resize(object sender, EventArgs e)
{
/*int columnWidth = (this.Width - (4 + (3 * this.file.Headers.Count))) / this.file.Headers.Count;
columnWidth--;
foreach (DataGridViewColumn column in this.grid.Columns)
{
column.Width = columnWidth;
}*/
}
private void grid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex < 0) || (e.RowIndex >= this.grid.Rows.Count))
{
return;
}
this.grid.Rows[e.RowIndex].Selected = true;
}
}
}