第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用右擊菜單列表的刪除刪除dgvShow選中的行(dgvShow沒有綁定數(shù)據(jù)庫是通過List<Stu>加載數(shù)據(jù)的)

使用右擊菜單列表的刪除刪除dgvShow選中的行(dgvShow沒有綁定數(shù)據(jù)庫是通過List<Stu>加載數(shù)據(jù)的)

C#
CodeSection 2015-11-14 22:23:21
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 窗體值傳遞{??? public partial class FrmShow : Form??? {??????? List<Stu> listStu = null;??????? FrmMain fMain = null;??????? DataTable dt = null;??????? int rowIndex = 0;??????? public FrmShow(FrmMain fMain)??????? {??????????? this.fMain = fMain;??????????? InitializeComponent();??????????? listStu = new List<Stu>();??????????? listStu.Add(new Stu("貂蟬", "女", "20"));??????????? listStu.Add(new Stu("張飛", "男", "22"));??????????? listStu.Add(new Stu("曹操", "男", "23"));??????????? listStu.Add(new Stu("呂布", "男", "12"));??????????? listStu.Add(new Stu("荀彧", "男", "23"));??????? }??????? private void FrmShow_Load(object sender, EventArgs e)??????? {??????????? this.dgvShow.DataSource = listStu;??????? }??????? private void btnTest_Click(object sender, EventArgs e)??????? {??????????? Stu s = null;??????????? this.dt = new DataTable();??????????? this.dt.Columns.Add("sName", Type.GetType("System.String"));??????????? this.dt.Columns.Add("sSex", Type.GetType("System.String"));??????????? this.dt.Columns.Add("sAge", Type.GetType("System.String"));??????????? //int j = 0;??????????? for (int i = 0; i < this.dgvShow.RowCount; i++)??????????? {??????????????? bool re_value = (bool)dgvShow.Rows[i].Cells[0].EditedFormattedValue;??????????????? //判斷勾選的 ??????????????? if (re_value)??????????????? {??????????????????? string sName = this.dgvShow.Rows[i].Cells[1].Value.ToString();??????????????????? string sSex = this.dgvShow.Rows[i].Cells[2].Value.ToString();??????????????????? string sAge = this.dgvShow.Rows[i].Cells[3].Value.ToString();??????????????????? this.dt.Rows.Add(new object[] { sName, sSex, sAge });??????????????? }??????????? }??????????? if (this.dt != null)??????????? {??????????????? //傳遞到主窗體,更新數(shù)據(jù)??????????????? this.fMain.Chang(this.dt);??????????????? //foreach (DataRow item in dt.Rows)??????????????? //{??????????????? //??? //this.fMain.AddRow(item);??????????????? //??? MessageBox.Show(item["sName"].ToString()+","+item["sSex"].ToString()+","+item["sAge"].ToString());??????????????? //}??????????????? this.Close();??????????? }??????? }??????? private void tsmi_Del_Click(object sender, EventArgs e)//右擊菜單列表的刪除??????? {??????????? this.rowIndex = this.dgvShow.CurrentRow.Index;??????????? MessageBox.Show("Test:" + this.rowIndex.ToString());??????????? /*???????????? * 以下執(zhí)行刪除算法???????????? * ???????????? * */??????????? //使用右擊菜單列表的刪除刪除dgvShow選中的行(dgvShow沒有綁定數(shù)據(jù)庫是通過List<Stu>加載數(shù)據(jù)的)??????????? if (dgvShow != null && dgvShow.CurrentCell != null && dgvShow.CurrentCell.RowIndex != -1)??????????? {??????????????? dgvShow.Rows.RemoveAt(dgvShow.CurrentCell.RowIndex);??????????? } //報錯??????????? //dgvShow.Rows.RemoveAt(rowIndex);??????? }??????? private void dgvShow_CellClick(object sender, DataGridViewCellEventArgs e)??????? {??????????? this.rowIndex = e.RowIndex;??????????? bool re_value = (bool)dgvShow.Rows[this.rowIndex].Cells[0].EditedFormattedValue;??????????? if (!re_value)??????????? {??????????????? this.dgvShow.Rows[this.rowIndex].Cells[0].Value = true;??????????? }??????????? else??????????? {??????????????? this.dgvShow.Rows[this.rowIndex].Cells[0].Value = false;??????????? }??????? }??????? private void dgvShow_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)??????? {??????????? if (e.Button == MouseButtons.Right)??????????? {??????????????? if (e.RowIndex >= 0)??????????????? {??????????????????? dgvShow.ClearSelection();??????????????????? dgvShow.Rows[e.RowIndex].Selected = true;??????????????????? //MessageBox.Show("Test:" + e.RowIndex.ToString());??????????????????? //string i = dgvShow.SelectedCells[0].Value.ToString();??????????????????? //MessageBox.Show(i);??????????????????? dgvShow.CurrentCell = dgvShow.Rows[e.RowIndex].Cells[e.ColumnIndex];??????????????????? contextMenuStrip.Show(MousePosition.X, MousePosition.Y);??????????????? }??????????? }??????? }??? }}
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 1971 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號