I am putting a list of event logs into the dataGridView
from windows froms, the program runs fine and it more or less does what it needs to do, but while it is putting it into the dataGridView
and while I am scrolling through the events in the dataGridView
it throws up a ton of errors.
Video of issue: https://youtu.be/Ixl7AatUiW0
I don't know where they are coming from or where to start to fix them. You can sort of scroll through the events, but it throws up those errors and keeps running.
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 });
}
Exceptions below:
The following exception occurred in the DataGridView:
System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at
System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptionContext context, CultureInfo culture, Object value)
at
System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType. TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue) at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at
System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle & cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
To replace this default dialog please handle the DataError event.
The following exception occurred in the DataGridView:
System.ArgumentException: The value '0' is not a valid value for the enum 'EventLogEntryType'.
at
System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
at
System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType. TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue) at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at
System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle & cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
To replace this default dialog please handle the DataError event.