手动生成datagridview

时间:2012-06-26 14:25:47
【文件属性】:

文件名称:手动生成datagridview

文件大小:25KB

文件格式:DOC

更新时间:2012-06-26 14:25:47

datagridview

手动生成datagridview private void PopulateDataGridView() { DataGridView1.Size = new Size(350, 400); DataGridView1.AllowUserToDeleteRows = true; // Add columns to the DataGridView. DataGridView1.ColumnCount = 4; DataGridView1.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; // Set the properties of the DataGridView columns. DataGridView1.Columns[0].Name = "Description"; DataGridView1.Columns[1].Name = "Withdrawals"; DataGridView1.Columns[2].Name = "Deposits"; DataGridView1.Columns[3].Name = "Balance"; DataGridView1.Columns["Description"].HeaderText = "Description"; DataGridView1.Columns["Withdrawals"].HeaderText = "W(-)"; DataGridView1.Columns["Deposits"].HeaderText = "D(+)"; DataGridView1.Columns["Balance"].HeaderText = "Balance"; DataGridView1.Columns["Balance"].ReadOnly = true; DataGridView1.Columns["Description"].SortMode = DataGridViewColumnSortMode.NotSortable; DataGridView1.Columns["Withdrawals"].SortMode = DataGridViewColumnSortMode.NotSortable; DataGridView1.Columns["Deposits"].SortMode = DataGridViewColumnSortMode.NotSortable; DataGridView1.Columns["Balance"].SortMode = DataGridViewColumnSortMode.NotSortable; // Add rows of data to the DataGridView. DataGridView1.Rows.Add(new string[] { "Starting Balance", "", "", "1000" }); DataGridView1.Rows.Add(new string[] { "Paycheck Deposit", "", "850", "" }); DataGridView1.Rows.Add(new string[] { "Rent", "-500", "", "" }); DataGridView1.Rows.Add(new string[] { "Groceries", "-25", "", "" }); DataGridView1.Rows.Add(new string[] { "Tax Return", "", "300", "" }); // Allow the user to edit the starting balance cell DataGridView1.Rows[0].ReadOnly = true; DataGridView1.Rows[0].Cells["Balance"].ReadOnly = false; // Autosize the columns. DataGridView1.AutoResizeColumns();


网友评论