在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、动态添加选项卡,并加载DataGridVIew,绑定数据 private void MainForm_Load(object sender, EventArgs e) { int newsId = 0; dtType = News_Release.News_BLL.BLL.Cmb_Type(newsId); for (int i = 0; i < dtType.Rows.Count; i++) { TabPage Page = new TabPage(); Page.Name = dtType.Rows[i]["Classification_ID"].ToString(); Page.Text = dtType.Rows[i]["Name"].ToString(); this.tcHomePage.Controls.Add(Page); if(i==0) { Page.Controls.Add(dataGridView1); this.dataGridView1.Dock = DockStyle.Fill; } } this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.ReadOnly = true; this.dataGridView1.DataSource = Login.BLL_Login.MainForm.selectedNews(Convert.ToInt32(dtType.Rows[0]["Classification_ID"].ToString())); } private void tcHomePage_SelectedIndexChanged(object sender, EventArgs e) { int newsClassification = Convert.ToInt32(tcHomePage.SelectedTab.Name); //string typeName = tcHomePage.SelectedTab.Text; tcHomePage.SelectedTab.Controls.Add(dataGridView1); this.dataGridView1.Dock = DockStyle.Fill; this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.DataSource = Login.BLL_Login.MainForm.selectedNews(newsClassification); }
2、新建一个WinForm程序,拖一个TabControl(在tabPages属性里面将默认的两个TabPage删除)和三个Button(增加、删除、修改)
|
请发表评论