private void boundItemList(IList <Record> recordList) { foreach (Record item in recordList) { ItemList.Items.Add(new ListViewItem(new string[] { item.Id.ToString(), item.Date.ToString("yyyy-MM-dd"), item.Spend == 0 ? "" : item.Spend.ToString("n"), item.Income == 0 ? "" : item.Income.ToString("n"), GetType(item.Type), item.Description })); ItemList.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.ColumnContent); ItemList.AutoResizeColumn(5, ColumnHeaderAutoResizeStyle.ColumnContent); } ImageList imgList = new ImageList(); imgList.ImageSize = new Size(1, 25); ItemList.SmallImageList = imgList; lvwColumnSorter.SortColumn = 1; lvwColumnSorter.Order = SortOrder.Descending; ItemList.Sort(); }
private void queryRecord() { IList <Record> recordList = rb.GetByDate(startDate, endDate, rtid, qt); if (ItemList.InvokeRequired) { queryRecordDelegate qrd = new queryRecordDelegate(queryRecord); this.Invoke(qrd); } else { ItemList.Clear(); ItemList.Columns.Add(null, 19, HorizontalAlignment.Left); ItemList.Columns.Add("日期", 70, HorizontalAlignment.Center); ItemList.Columns.Add("支出", 100, HorizontalAlignment.Right); ItemList.Columns.Add("收入", 100, HorizontalAlignment.Right); ItemList.Columns.Add("类型", 150, HorizontalAlignment.Left); ItemList.Columns.Add("说明", 200, HorizontalAlignment.Left); foreach (Record item in recordList) { ItemList.Items.Add(new ListViewItem(new string[] { item.Id.ToString(), item.Date.ToString("yyyy-MM-dd"), item.Spend == 0 ? "" : item.Spend.ToString("n"), item.Income == 0 ? "" : item.Income.ToString("n"), GetType(item.Type), item.Description })); ItemList.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.ColumnContent); ItemList.AutoResizeColumn(5, ColumnHeaderAutoResizeStyle.ColumnContent); } ImageList imgList = new ImageList(); imgList.ImageSize = new Size(1, 25); ItemList.SmallImageList = imgList; lvwColumnSorter.SortColumn = 1; lvwColumnSorter.Order = SortOrder.Descending; ItemList.Sort(); ItemList.Enabled = true; queryStartDate.Enabled = true; queryEndDate.Enabled = true; cboxUnits.Enabled = true; cboxRecordType.Enabled = true; btnQuery.Enabled = true; labItemList.Visible = false; } }