if(e.ColumnIndex == 1) { SaleTerminalSetting.SpName =splistracmas; SaleTerminalSetting.OpCodeValue = 2; SaleTerminalSetting.ListTitle = @股票帮助; frmList2 objTemp = new frmList2(); objTemp.ShowDialog(this); for(int i = 0; i< = griddetail.Rows.Count - 1; i ++) { griddetail.Rows [i] .Cells [1] .Value = SaleTerminalSetting.ListCode.Trim()。ToUpper(); griddetail.Rows [i] .Cells [2 ] .Value = SaleTerminalSetting.ListDescription.Trim()。ToUpper(); } order = order.Find_Rec(SaleTerminalSetting.ListCode); for(int i = 0; i< = griddetail.Rows.Count - 1; i ++) { griddetail.Rows [i] .Cells [4] .Value = order.uom; griddetail.Rows [i ] .Cells [5] .Value = order.rate; griddetail.Rows [i] .Cells [7] .Value = order.sales_tax; decimal qty = Convert.ToDecimal(griddetail.Rows [i] .Cells [3] .Value); decimal rate = Convert.ToDecimal(order.rate); griddetail.Rows [i] .Cells [9] .Value = order.store_sec; } //griddetail.NotifyCurrentCellDirty(true); } if(BtnModify.Enabled == true) { for(int i = 0; i< = griddetail.Rows.Count - 2; i ++) { double vat = 0 ; double total = 0; double disc = 0; string code = griddetail.Rows [i] .Cells [1]。 Value.ToString(); order = order.Find_Rec(code); if(e.ColumnIndex == 3) { frmCancelBillKb kb = new frmCancelBillKb(); kb.ShowDialog(); griddetail.Rows [i] .Cells [3] .Value = SaleTerminalSetting.Remarks; if(griddetail.Rows [i] .Cells [3]。值!= null) { 十进制数量= Convert.ToDecimal(griddetail.Rows [i] .Cells [3] .Value); decimal rate = order.rate; string amt =(qty * rate).ToString(); griddetail.Rows [i] .Cells [8]。 Value = amt.ToString(); total = total + Convert.ToDouble(griddetail.Rows [i] .Cells [8] .Value); decimal rate1 = Convert.ToDecimal(griddetail.Rows [i] .Cells [8] .Value); decimal vat1 = Convert.ToDecimal(griddetail.Rows [i] .Cells [7] .Value); double vatamt = Convert.ToDouble((rate1 * vat1)/ 100); vat = vat + vatamt; decimal discper = Convert.ToDecimal(griddetail.Rows [i] .Cells [6] .Value); double discount = Convert.ToDouble((rate1 * discper)/ 100); disc = disc + discount; txttotamt.Text = total .ToStr ing(); txtvat.Text = vat.ToString(); txtdisc.Text = disc.ToString(); txtnetamt。 Text =((Convert.ToDecimal(txttotamt.Text)+ Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal(txtdisc.Text))。ToString(); } } if(e.ColumnIndex == 6) { frmCancelBillKb kb1 = new frmCancelBillKb(); kb1.ShowDialog(); griddetail.Rows [i] .Cells [6] .Value = SaleTerminalSetting 。备注; txttotamt.Text = totalPrice()。ToString(); txtvat.Text = totalVAT()。ToString(); txtdisc.Text = totaldisc()。ToString(); txtnetamt.Text =((Convert.ToDecimal(txttotamt.Text)+ Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal( txtdisc.Text))。ToString(); } } } for(int i = 0; i == griddetail.Rows.Count - 1; i ++) { if(e.ColumnIndex == 3) { frmCancelBillKb kb = new frmCancelBillKb(); kb.ShowDialog(); griddetail.Rows [i] .Cells [ 3] .Value = SaleTerminalSetting.Remarks; if(griddetail.Rows [i] .Cells [3] .Value!= null) { decimal qty = Convert.ToDecimal(griddetail.Rows [i] .Cells [3] .Value); decimal rate = order.rate; string amt =(qty * rate).ToString(); griddetail.Rows [i] .Cells [8] .Value = amt.ToString(); } } if(e .ColumnIndex == 6) { frmCancelBillKb kb1 = new frmCancelBillKb(); kb1.ShowDialog(); griddetail.Rows [i] .Cells [6] .Value = SaleTerminalSetting.Remarks; } txttotamt.Text = totalPrice()。ToString(); txtvat.Text = totalVAT()。ToString(); txtdisc.Text = totaldisc() .ToString(); txtnetamt.Text =((Convert.ToDecimal(txttotamt.Text)+ Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal(txtdisc.Text))。ToString( ); } } ThnaksHello All,I have a datagrid view and i want to add a new row below the selected row .pls help me..Here is the code, please tell me how to add a new row below the current row.private void griddetail_CellClick(object sender, DataGridViewCellEventArgs e){if (e.ColumnIndex == 1){SaleTerminalSetting.SpName = "splistracmas";SaleTerminalSetting.OpCodeValue = 2;SaleTerminalSetting.ListTitle = @"Stock Help";frmList2 objTemp = new frmList2();objTemp.ShowDialog(this);for (int i = 0; i <= griddetail.Rows.Count - 1; i++){griddetail.Rows[i].Cells[1].Value = SaleTerminalSetting.ListCode.Trim().ToUpper();griddetail.Rows[i].Cells[2].Value = SaleTerminalSetting.ListDescription.Trim().ToUpper();}order = order.Find_Rec(SaleTerminalSetting.ListCode);for (int i = 0; i <= griddetail.Rows.Count - 1; i++){griddetail.Rows[i].Cells[4].Value = order.uom;griddetail.Rows[i].Cells[5].Value = order.rate;griddetail.Rows[i].Cells[7].Value = order.sales_tax;decimal qty = Convert.ToDecimal(griddetail.Rows[i].Cells[3].Value);decimal rate = Convert.ToDecimal(order.rate);griddetail.Rows[i].Cells[9].Value = order.store_sec;}//griddetail.NotifyCurrentCellDirty(true);}if (BtnModify.Enabled == true){for (int i = 0; i <= griddetail.Rows.Count - 2; i++){double vat = 0;double total = 0;double disc = 0;string code = griddetail.Rows[i].Cells[1].Value.ToString();order = order.Find_Rec(code);if (e.ColumnIndex == 3){frmCancelBillKb kb = new frmCancelBillKb();kb.ShowDialog();griddetail.Rows[i].Cells[3].Value = SaleTerminalSetting.Remarks;if (griddetail.Rows[i].Cells[3].Value != null){decimal qty = Convert.ToDecimal(griddetail.Rows[i].Cells[3].Value);decimal rate = order.rate;string amt = (qty * rate).ToString();griddetail.Rows[i].Cells[8].Value = amt.ToString();total = total + Convert.ToDouble(griddetail.Rows[i].Cells[8].Value);decimal rate1 = Convert.ToDecimal(griddetail.Rows[i].Cells[8].Value);decimal vat1 = Convert.ToDecimal(griddetail.Rows[i].Cells[7].Value);double vatamt = Convert.ToDouble((rate1 * vat1) / 100);vat = vat + vatamt;decimal discper = Convert.ToDecimal(griddetail.Rows[i].Cells[6].Value);double discount = Convert.ToDouble((rate1 * discper) / 100);disc = disc + discount;txttotamt.Text = total.ToString();txtvat.Text = vat.ToString();txtdisc.Text = disc.ToString();txtnetamt.Text = ((Convert.ToDecimal(txttotamt.Text) + Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal(txtdisc.Text)).ToString();}}if (e.ColumnIndex == 6){frmCancelBillKb kb1 = new frmCancelBillKb();kb1.ShowDialog();griddetail.Rows[i].Cells[6].Value = SaleTerminalSetting.Remarks;txttotamt.Text = totalPrice().ToString();txtvat.Text = totalVAT().ToString();txtdisc.Text = totaldisc().ToString();txtnetamt.Text = ((Convert.ToDecimal(txttotamt.Text) + Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal(txtdisc.Text)).ToString();}}}for (int i = 0; i == griddetail.Rows.Count - 1; i++){if (e.ColumnIndex == 3){frmCancelBillKb kb = new frmCancelBillKb();kb.ShowDialog();griddetail.Rows[i].Cells[3].Value = SaleTerminalSetting.Remarks;if (griddetail.Rows[i].Cells[3].Value != null){decimal qty = Convert.ToDecimal(griddetail.Rows[i].Cells[3].Value);decimal rate = order.rate;string amt = (qty * rate).ToString();griddetail.Rows[i].Cells[8].Value = amt.ToString();}}if (e.ColumnIndex == 6){frmCancelBillKb kb1 = new frmCancelBillKb();kb1.ShowDialog();griddetail.Rows[i].Cells[6].Value = SaleTerminalSetting.Remarks;}txttotamt.Text = totalPrice().ToString();txtvat.Text = totalVAT().ToString();txtdisc.Text = totaldisc().ToString();txtnetamt.Text = ((Convert.ToDecimal(txttotamt.Text) + Convert.ToDecimal(txtvat.Text)) - Convert.ToDecimal(txtdisc.Text)).ToString();}}Thnaks推荐答案您可以调用 dataGridView1.Rows.Add()在DataGrid中添加行的函数。 通过 Prasad_Kulkarni :在DataGridView中添加行(带有预定义列) [ ^ ]。 并检查一个类似的线程 here [ ^ ]。 希望它有所帮助! - AmitYou can call dataGridView1.Rows.Add() function to add a row in DataGrid.See a similar solution by Prasad_Kulkarni : Add Row in DataGridView ( with Predefined Columns)[^].And also check a similar thread here[^].Hope it helps!--Amit datagridview1.Rows.add(); 这将有助于在datagridview中添加新的datarowdatagridview1.Rows.add();This will help to add new datarow in datagridview试试这个Try thisDataTable ds = (DataTable)dataGridView1.DataSource; DataRow dr = ds.NewRow();//index is selected row's index ds.Rows.InsertAt(dr, index + 1); dataGridView1.DataSource = ds; 这篇关于如何在C#win表单中向数据网格视图添加空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-22 07:53