List.
1. MS Visual Studio 2008 .
2. Windows Forms.
1.1
, 1.2
1.2
3. ( Text, - BackColor).
4. SplitContainer c . 2 . , . 1.3.
1.3 SplitContainer
5. Panel1 Panel2 Panel c , Dock Fill. , . DataGridView .
6. DataGridView Dock Fill. , TextBox Button. . Label. 1.4.
1.4
7. , . Student ( => , 1.5).
1.5
:
namespace lab1
{
class Student
{
private string name;
private string surname;
private string recordBookNumber;
public Student(string name, string surname, string recordBookNumber)
{
this.name = name;
this.surname = surname;
this.recordBookNumber = recordBookNumber;
}
public string getName()
{
return this.name;
}
public string getSurname()
{
return this.surname;
}
public string getRecordBookNumber()
{
return this.recordBookNumber;
}
public void setName(string name)
{
this.name = name;
}
public void setSurname(string surname)
{
this.surname = surname;
}
public void setRecordBookNumber(string recordBookNumber)
{
this.recordBookNumber = recordBookNumber;
}
}
}
8. ContextMenuStip ( ), ContextMenuStip DataGridView contextMenuStip1. DataGridView .
|
|
9. DataGridView : ReadOnly True, MultiSelect False, RowHeadersVisible False, SelectionMode FullRowSelect.
10. DataGridView DataGridViewColumn DataGridViewRow. , DataGridView , . DataGridView . , .
( Form1.cs , , CSharp).
:
//
private DataGridViewColumn dataGridViewColumn1 = null;
private DataGridViewColumn dataGridViewColumn2 = null;
private DataGridViewColumn dataGridViewColumn3 = null;
:
//
private void initDataGridView()
{
dataGridView1.DataSource = null;
dataGridView1.Columns.Add(getDataGridViewColumn1());
dataGridView1.Columns.Add(getDataGridViewColumn2());
dataGridView1.Columns.Add(getDataGridViewColumn3());
dataGridView1.AutoResizeColumns();
}
//
private DataGridViewColumn getDataGridViewColumn1()
{
if (dataGridViewColumn1 == null)
{
dataGridViewColumn1 = new DataGridViewTextBoxColumn();
dataGridViewColumn1.Name = "";
dataGridViewColumn1.HeaderText = "";
dataGridViewColumn1.ValueType = typeof(string);
dataGridViewColumn1.Width = dataGridView1.Width / 3;
}
return dataGridViewColumn1;
}
//
private DataGridViewColumn getDataGridViewColumn2()
{
if (dataGridViewColumn2 == null)
{
dataGridViewColumn2 = new DataGridViewTextBoxColumn();
dataGridViewColumn2.Name = "";
dataGridViewColumn2.HeaderText = "";
dataGridViewColumn2.ValueType = typeof(string);
dataGridViewColumn2.Width = dataGridView1.Width / 3;
}
return dataGridViewColumn2;
}
//
private DataGridViewColumn getDataGridViewColumn3()
{
if (dataGridViewColumn3 == null)
{
dataGridViewColumn3 = new DataGridViewTextBoxColumn();
dataGridViewColumn3.Name = "";
dataGridViewColumn3.HeaderText = "";
dataGridViewColumn3.ValueType = typeof(string);
dataGridViewColumn3.Width = dataGridView1.Width / 3;
}
return dataGridViewColumn3;
}
dataGridView1 , .
initDataGridView:
public Form1()
{
InitializeComponent();
initDataGridView();
}
11. , :
// List
private IList<Student> studentList = new List<Student>();
12. DataGridView:
//
private void addStudent(string name, string surname, string
|
|
recordBookNumber)
{
Student s = new Student(name, surname, recordBookNumber);
studentList.Add(s);
textBox1.Text = "";
textBox2.Text = "";
textBox2.Text = "";
showListInGrid();
}
//
private void deleteStudent(int elementIndex)
{
studentList.RemoveAt(elementIndex);
showListInGrid();
}
//
private void showListInGrid()
{
dataGridView1.Rows.Clear();
foreach (Student s in studentList)
{
DataGridViewRow row = new DataGridViewRow();
DataGridViewTextBoxCell cell1 = new
DataGridViewTextBoxCell();
DataGridViewTextBoxCell cell2 = new
DataGridViewTextBoxCell();
DataGridViewTextBoxCell cell3 = new
DataGridViewTextBoxCell();
cell1.ValueType = typeof(string);
cell1.Value = s.getName();
cell2.ValueType = typeof(string);
cell2.Value = s.getSurname();
cell3.ValueType = typeof(string);
cell3.Value = s.getRecordBookNumber();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);
dataGridView1.Rows.Add(row);
}
}
13. :
//
private void button1_Click(object sender, EventArgs e)
{
addStudent(textBox1.Text, textBox2.Text, textBox3.Text);
}
//
private void ToolStripMenuItem_Click(object sender,
EventArgs e)
{
int selectedRow = dataGridView1.SelectedCells[0].RowIndex;
DialogResult dr = MessageBox.Show(" ?", "",
MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
try
{
deleteStudent(selectedRow);
}
catch (Exception)
{
}
}
}
1.6.
1.6
, .
, . , , 1.2. 5- . .
. , .
1.2
HashSet<T> | ||
LinkedList<T> | ||
Dictionary<TKey, TValue> | ||
Queue<T> | ||
SortedDictionary<TKey, TValue> | ||
SortedList<TKey, TValue> | ||
SortedSet<T> | ||
Stack<T> | ||
HashSet<T> | ||
LinkedList<T> |
- ;
- ;
- ;
- ;
- ( , );
- .
1. ?
2. .NET?
3. ?
4. ?
5. ?
2 2
C#, #.
|
|
(assembly) - .NET Framework , , . :
- ;
- ;
- IL.
.NET .exe .dll , . , ( .exe), ( .dll). .
- , , , . , ( , ). , , .
, , . , , - .
CLR.
2.1.
2.1 -