-1

私のwinformアプリには、2つのタブとマルチスレッドがあります。1つはメインタブで、もう1つはログタブです。datagridviewコントロールにログを表示するためにログタブのみを使用します。クリックしてログタブ(行または列をクリックしない)で例外がランダムに発生しました。試しましたが、修正する方法が見つかりません。これはエラーログです:

Message : Object reference not set to an instance of an object.
Source : System.Windows.Forms
TargetSite : System.Windows.Forms.DataGridViewElementStates GetRowState(Int32)
StackTrace :    at System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)
   at System.Windows.Forms.DataGridView.ComputeHeightOfFittingTrailingScrollingRows(Int32 totalVisibleFrozenHeight)
   at System.Windows.Forms.DataGridView.GetOutOfBoundCorrectedHitTestInfo(HitTestInfo& hti, Int32& mouseX, Int32& mouseY, Int32& xOffset, Int32& yOffset)
   at System.Windows.Forms.DataGridView.OnMouseMove(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseMove(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Message : Object reference not set to an instance of an object.
Source : System.Windows.Forms
TargetSite : Void ClearInternal(Boolean)
StackTrace :    at System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean recreateNewRow)
   at System.Windows.Forms.DataGridView.OnClearingColumns()
   at System.Windows.Forms.DataGridViewColumnCollection.Clear()
   at System.Windows.Forms.DataGridView.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.TabControl.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)

ステータスコードの更新:

    private void updateMessage(int index, string message)
    {
        try
        {
            this.dgForums.Rows[index].Cells["ColStatus"].Value = message;

            System.Windows.Forms.Application.DoEvents();
        }
        catch
        {
        }
    }
4

1 に答える 1

0

グリッド クリック イベントまたはグリッドに関連するその他のイベントの行と列以外のグリッドでクリックした場合、コードの前にコードを追加します。

if(this.dgForums.Rows.Count > 0)
{
  //Continue your code here
}
于 2012-10-20T04:57:54.720 に答える