我將事件日誌列表放入dataGridView
中,程序運行正常,它或多或少地完成了它需要做的事情,但是當它將它放入dataGridView
當我滾動瀏覽dataGridView
中的事件時,它會引發大量錯誤。將事件日誌傳入dataGridView時的錯誤
我不知道在哪裏,他們都來自或從哪裏開始解決這些問題。 您可以對事件進行滾動瀏覽,但會拋出這些錯誤並繼續運行。
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事件。
如果您將異常痕跡納入問題中,將會非常有幫助 – klashar
有多個例外我將視頻與他們關聯在一起,但我會在代碼下方編寫例外,以便您也可以閱讀它們。 –