Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Bài giảng Lập trình C# 2010: Chương 2.4 trình bày cách thức thực hiện, câu lệnh, nút lệnh và tính năng của các nút lệnh cùng một số nội dung khác về Windows Forms and Windows Forms Controls. | 1 btnHeader btnAdd btnRemove lvDataDn txtID txtName dateBirthDay ListView 2 private void btnLoadHeader_Click (object sender, EventArgs e) { ColumnHeader hdID = new ColumnHeader(); hdID.Text = "ID"; ColumnHeader hdName = new ColumnHeader(); hdName.Text = "Name"; ColumnHeader hdBirthday = new ColumnHeader(); hdBirthday.Text = "Birthday"; 3 lvDataDn.GridLines = true; lvDataDn.FullRowSelect = true; lvDataDn.MultiSelect = true; lvDataDn.HideSelection = false; lvDataDn.View = View.Details; hdID.Width = 100; hdName.Width =140; hdBirthday.Width = 140; lvDataDn.Columns.Clear(); 4 lvDataDn.Columns.AddRange(new ColumnHeader[] { hdID,hdName,hdBirthday}); } At Design Time ???? 5 private void btnAdd_Click (object sender, EventArgs e) { ListViewItem itemID = new ListViewItem(); itemID.Text = txtID.Text; ListViewItem.ListViewSubItem itemName = new ListViewItem.ListViewSubItem(); itemName.Text=txtName.Text; itemID.SubItems.Add(itemName); 6 ListViewItem.ListViewSubItem itemBirthday = new ListViewItem.ListViewSubItem(); itemBirthday.Text = dateBirthDay.Value.Day + "/" + dateBirthDay.Value.Month + "/" + dateBirthDay.Value.Year; itemID.SubItems.Add(itemBirthday); lvDataDn.Items.Add(itemID); } 7 private void btnRemove_Click (object sender, EventArgs e) {ListView. SelectedListViewItemCollection list = lvDataDn.SelectedItems; foreach (ListViewItem item in list) lvDataDn.Items.Remove(item); } 8 ListView.SelectedIndexCollection indices = lvDataDn.SelectedIndices; foreach (int index in indices) { //Process Index here } We could use Indices 9 TreeView 10 ImageList SelectedNode TreeNode ImageIndex SelectedImageIndex Nodes Remove Add Expand Collapse Popular Properties & Method 11 private void frmTreeView_Load (object sender, EventArgs e) {cboImageIndex.Items.Clear(); for (int i = 0; i < imgList.Images.Count;i++ ) { cboImageIndex.Items.Add(i); } tvSample.ImageList = imgList; } 12 private void btnAddRoot_Click (object sender, EventArgs e) {tvSample.Nodes.Clear(); TreeNode rootNode = new TreeNode(txtRoot.Text); rootNode.ImageIndex = Int32.Parse(cboImageIndex.Text); rootNode.SelectedImageIndex = rootNode.ImageIndex; tvSample.Nodes.Add(rootNode); txtRoot.Text = ""; } 13 private void cboImageIndex_SelectedIndexChanged(object sender, EventArgs e) { picShow.Image=imgList.Images[Int32.Parse(cboImageIndex.Text)]; } 14 private void btnRemove_Click(object sender, EventArgs e) { TreeNode tNode = tvSample.SelectedNode; tvSample.Nodes.Remove(tNode); } 15 END 16 | 1 btnHeader btnAdd btnRemove lvDataDn txtID txtName dateBirthDay ListView 2 private void btnLoadHeader_Click (object sender, EventArgs e) { ColumnHeader hdID = new ColumnHeader(); hdID.Text = "ID"; ColumnHeader hdName = new ColumnHeader(); hdName.Text = "Name"; ColumnHeader hdBirthday = new ColumnHeader(); hdBirthday.Text = "Birthday"; 3 lvDataDn.GridLines = true; lvDataDn.FullRowSelect = true; lvDataDn.MultiSelect = true; lvDataDn.HideSelection = false; lvDataDn.View = View.Details; hdID.Width = 100; hdName.Width =140; hdBirthday.Width = 140; lvDataDn.Columns.Clear(); 4 lvDataDn.Columns.AddRange(new ColumnHeader[] { hdID,hdName,hdBirthday}); } At Design Time ???? 5 private void btnAdd_Click (object sender, EventArgs e) { ListViewItem itemID = new ListViewItem(); itemID.Text = txtID.Text; ListViewItem.ListViewSubItem itemName = new ListViewItem.ListViewSubItem(); itemName.Text=txtName.Text; itemID.SubItems.Add(itemName); 6 ListViewItem.ListViewSubItem itemBirthday = new .