亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

DatagridView:無法刪除行

DatagridView:無法刪除行

C#
慕田峪7331174 2021-04-27 16:12:37
我想清除數據網格視圖而不刪除列設置。一欄是DataGridViewComboBoxColumn。我使用以下代碼:gridNomiColonne.Rows.Clear();gridNomiColonne.Columns.Clear();我收到以下錯誤:"Cannot delete data" ( System.ArgumentExceptionHResult=0x80070057Messaggio=Impossibile cancellare questo elenco.Origine=System.DataAnalisi dello stack:in System.Data.DataView.System.Collections.IList.Clear()in System.Windows.Forms.BindingSource.Clear()in System.Windows.Forms.DataGridViewRowCollection.Clear()in ContabImporterf.MainForm.btnCarica_Click(Object sender, EventArgs e) inC:\Users\Utente\Documents\Visual Studio 2017\Projects\ContabImporterf\ContabImporterf\MainForm.cs: riga 200in System.Windows.Forms.Control.OnClick(EventArgs e)in System.Windows.Forms.Button.OnClick(EventArgs e)in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)in System.Windows.Forms.Control.WndProc(Message& m)in System.Windows.Forms.ButtonBase.WndProc(Message& m)in System.Windows.Forms.Button.WndProc(Message& m)in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32msg, IntPtr wparam, IntPtr lparam)in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)in      Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNaiiveMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32reason, Int32 pvLoopData)in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32reason, ApplicationContext context)in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)in System.Windows.Forms.Application.Run(Form mainForm)in ContabImporterf.Program.Main() in C:\Users\Utente\Documents\Visual Studio2017\Projects\ContabImporterf\ContabImporterf\Program.cs: riga 19 )有任何想法嗎?
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

您可以使用類似:

gridNomiColonne.DataSource = (gridNomiColonne.DataSource as DataTable).Clone();

這將刪除網格中的所有行,但將保留表的結構。

如果您想清除所有數據,可以使用

gridNomiColonne.DataSource= null;


查看完整回答
反對 回復 2021-05-08
  • 1 回答
  • 0 關注
  • 302 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號