2017-03-07 49 views
0

我將事件日誌列表放入dataGridView中,程序運行正常,它或多或少地完成了它需要做的事情,但是當它將它放入dataGridView當我滾動瀏覽dataGridView中的事件時,它會引發大量錯誤。將事件日誌傳入dataGridView時的錯誤

視頻問題:https://youtu.be/Ixl7AatUiW0

我不知道在哪裏,他們都來自或從哪裏開始解決這些問題。 您可以對事件進行滾動瀏覽,但會拋出這些錯誤並繼續運行。


public static class EventLogClassContainer 
{ 
    public static string EvlLocation { get; set; } = ""; 
    public static string EvlName { get; set; } = "Application"; 
    public static string evlLocationManual = "%Test.evt%"; 
    public static List<EventLogEntry> _LogEntries { get; private set; } 

    public static void ReadEventLog() 
    { 
     EventLog evlLog = new EventLog(EvlName, "."); 
     EventLogEntryCollection eventLogEntries = evlLog.Entries; 
     int eventLogEntryCount = eventLogEntries.Count; 
     foreach (EventLogEntry entry in evlLog.Entries) 
     { 
      //entry.Message 
      _LogEntries = eventLogEntries.Cast<EventLogEntry>().ToList(); 
     } 
    } 

    public static void SetEvlName(string evlLocation) 
    { 
     Parser.FileNameFinder(evlLocation, 3); 
    } 

    public static void RELSystemTest() 
    { 
     EventLog evlLog = new EventLog("Application", "."); 
     EventLogEntryCollection eventLogEntries = evlLog.Entries; 
     int eventLogEntryCount = eventLogEntries.Count; 
     _LogEntries = eventLogEntries.Cast<EventLogEntry>().ToList(); 
    } 

    public static void ParseTest() 
    { 
     evlLocationManual = "K:\\Event Log\\Test\\Test.evt"; 
     ReadEventLog(); 
    } 

    public static void setLogLocation(string input) 
    { 
     EvlLocation = input; 
    } 
} 

// Open the log file 
    private void OpenFile() 
    { 
     // Show file open dialog 
     if (openFile.ShowDialog() == DialogResult.OK) 
     { 
      // Create a dataset for binding the data to the grid. 
      ds = new DataSet("EventLog Entries"); 
      ds.Tables.Add("Events"); 
      ds.Tables["Events"].Columns.Add("ComputerName"); 
      ds.Tables["Events"].Columns.Add("EventId"); 
      ds.Tables["Events"].Columns.Add("EventType"); 
      ds.Tables["Events"].Columns.Add("SourceName"); 
      ds.Tables["Events"].Columns.Add("Message"); 
      // Start the processing as a background process 
      EventLogClassContainer.EvlLocation = openFile.FileName; 
      worker.RunWorkerAsync(openFile.FileName); 
     } 
    } 

    // Bind the dataset to the grid. 
    private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
    { 
     EventLogClassContainer.RELSystemTest(); 
     bs = new BindingSource(ds, "Events"); 
     Foo foo1 = new Foo("TEST PC"); 
     ComputerName.Add(foo1); 

     bs.DataSource = EventLogClassContainer._LogEntries; 
     //Bind fooList to the dataGridView 
     dataGridView1.DataSource = bs; 

     this.Invoke(pbHandler, new object[] { 100, 100 }); 
    } 

以下例外情況:

下異常發生在DataGridView:

System.ArgumentException:參數無效。在System.Drawing.Image.FromStream(流流,布爾useEmbeddedColorManagement,布爾validateImageData)

System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptionContext上下文,CultureInfo的文化,對象的值)

在System.Windows.Forms.Formatter.FormatObject(Object value,T)中的System.Windows.Forms.Formatter.FormatObjectInternal(Object value,Type targetType。TypeConverter sourceConverter,TypeConverter targetConverter,String formatString,IFormatProvider formatInfo,Object formattedNullValue)

YPE TARGETTYPE,的TypeConverter sourceConverter,的TypeConverter targetConverter,字符串formatString的,的IFormatProvider formatInfo,對象formattedNullValue,對象dataSourceNullValue)

System.Windows.Forms.DataGridViewCell.GetFormattedValue(對象值,的Int32 rowIndex位置,的DataGridViewCellStyle & cellStyle, TypeConverter valueTypeConverter,TypeConverter formattedValueTypeConverter,DataGridViewDataErrorContexts context)

要替換此默認對話框,請處理DataError事件。


下異常發生在DataGridView:

System.ArgumentException:值 '0' 不是枚舉 'EventLogEntryType' 的有效值。

System.ComponentModel.EnumConverter。的ConvertTo(ITypeDescriptorContext方面,CultureInfo的文化,對象的值,類型destinationType)

System.Windows.Forms.Formatter.FormatObjectInternal(對象值,類型TARGETTYPE。的TypeConverter sourceConverter,的TypeConverter targetConverter,字符串formatString的,的IFormatProvider formatInfo在System.Windows.Forms.Formatter.FormatObject(對象值,類型TARGETTYPE,的TypeConverter sourceConverter,的TypeConverter targetConverter,字符串formatString的,的IFormatProvider formatInfo在

對象formattedNullValue),對象formattedNullValue,對象dataSourceNullValue)

System.Windows.Forms.DataGridViewCell.GetFormattedValue(對象價值的Int32的rowIndex,的DataGridViewCellStyle & cellStyle,類型轉換器valueTypeConverter,類型轉換器formattedValueTypeConverter,DataGridViewDataErrorContexts上下文)

要替換此默認對話框,請處理DataError事件。

+1

如果您將異常痕跡納入問題中,將會非常有幫助 – klashar

+0

有多個例外我將視頻與他們關聯在一起,但我會在代碼下方編寫例外,以便您也可以閱讀它們。 –

回答

0

從視頻中可以看出,某些列定義與文件內容不匹配。其中一列似乎期待圖像或圖標,但可能會得到某種類型的索引。另一列試圖將文件值轉換爲枚舉,但值「0」不在枚舉中。