Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

----------------------------------------------------------------------------------------------------------

C#
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;
        }
    }

----------------------------------------------------------------------------------------------------------

C#
// 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.

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.
Posted
Updated 13-Mar-17 12:29pm
v2
Comments
scudd_ 9-Mar-17 17:31pm    
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.
Patrice T 9-Mar-17 17:47pm    
You don't know what is debugging
CHill60 10-Mar-17 2:26am    
Read the article and you might realise just how silly your comment is ..."it runs fine, it just throws up exceptions" is a paradox
j snooze 9-Mar-17 17:36pm    
May I suggest adding try{}catch(Exception ex){} in each of your methods around your code and do some error handling. Do a MessageBox.Show("MethodName: " + ex.Message) then you'll know where its coming from and the error message.

1 solution

Quote:
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.

Your code don't fine because it throw errors.
The debugger don't pick any error, it just show you what is doing your code.
It is your duty to check that it do what it is supposed to do.
-----
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900