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)
{
_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;
}
}
----------------------------------------------------------------------------------------------------------
private void OpenFile()
{
if (openFile.ShowDialog() == DialogResult.OK)
{
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");
EventLogClassContainer.EvlLocation = openFile.FileName;
worker.RunWorkerAsync(openFile.FileName);
}
}
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;
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.
What I have tried:
I have tried going through each individual
EventLogEntry
with no success. The data from the
List<EventLogEntry>
seems to not match up with what dataGridView is calling for. It seems dataGridView is looking for an image for data which isn't there. I've tried debugging, but it isn't picking up any errors it runs fine, it just throws up exceptions every other click and I can't tell where it is coming from.
How can I get this to work properly without all the errors.