将事件登录到DataGridView时错误



我将事件日志的列表从Windows的windows列入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(流stream,Boolean useembeddedcolormanagement,boolean dicatibleanimimimagedata)

at

system.drawing.imageconverter.convertfrom(ItypedEscriptionContext上下文,文化文化,对象价值)

at

system.windows.forms.formater.formatObjectInternal(对象值,类型targetType。typeconverter sourceconverter,typeconverter targetConverter,string formattring,iformatProvider formatinfo,object object formattednullvalue),TypeConverter SourceConverter,TypeConverter TargetConverter,字符串格式,IformatProvider Formatinfo,对象formattednullvalue,对象datasourcenullvalue)

at

system.windows.forms.datagridviewcell.getFormattedValue(对象值,int32 rowIndex,dataGridViewCellStyle&amp; cellstyle,typeConverter valueTypeconverter,typececonverter,typececonverter forteconverter forceeconverter forceconeTedValuetyvaluetypepeconvertextext expce 替换此默认对话框,请处理DataError事件。


DataGridView中发生以下例外:

system.argumentException:值'0'不是枚举'eventLogenTryType'的有效值。

at

system.componentmodel.enumconverter.convertto(Itypedescriptorcontext上下文,cultureinfo文化,对象价值,键入destination typepe)

at

system.windows.forms.formater.formatObjectInternal(对象值,类型targetType。typeconverter sourceconverter,typeconverter targetConverter,string formattring,iformatProvider formatinfo,object object formattednullvalue),TypeConverter SourceConverter,TypeConverter TargetConverter,字符串格式,IformatProvider Formatinfo,对象formattednullvalue,对象datasourcenullvalue)

at

system.windows.forms.datagridviewcell.getFormattedValue(对象值,int32 rowIndex,dataGridViewCellStyle&amp; cellstyle,typeConverter valueTypeconverter,typececonverter,typececonverter forteconverter forceeconverter forceconeTedValuetyvaluetypepeconvertextext expce 替换此默认对话框,请处理DataError事件。

从视频中,看来您的某些列定义与文件内容不匹配。其中一列似乎是期望图像或图标,但可能会得到某种类型的索引。另一列是试图将文件值转换为枚举,但值" 0"不在枚举中。

最新更新