Krypton-Suite / Standard-Toolkit

An update to Component factory's krypton toolkit to support .NET Framework 4.6.2 - 4.8.1 to .NET 6 - 8
BSD 3-Clause "New" or "Revised" License
403 stars 61 forks source link

[Bug]: DataGridView freeze my form #557

Closed criss02-cs closed 2 years ago

criss02-cs commented 2 years ago

Describe the bug When I try to populate a KryptonDataGridView with a DataTable that will freeze my form and I can't do anything

DarthVader85PA commented 2 years ago

Can you please provide your code? It worked fine in my test. Which version of Krypton are you using? Which TFM? Which VisualStudio Version?

Here a Mini-Example: KryptonTest.zip

Greetings DarthVader :)

criss02-cs commented 2 years ago

Hi, List<User> users = JsonConvert.DeserializeObject<List<User>>(_json, settings);DataTable dt = users.ToDataTable();dgvList.DataSource = dt;dgvList.RowHeadersVisible = false; This is my code. I'm using VisualStudio2019, and I think I'm using the last version of Krypton I have installed from your's github. I don't know how to let you know which TFM i'm using

criss02-cs commented 2 years ago

I saw your example, you are using VB but I'm using C#

DarthVader85PA commented 2 years ago

Hi,

Is users.ToDataTable() a extension to a List-Class? I don't know this command/function on a List-Class-Object. Is your Deserialization of the JSON-Object works fine? You got a List of User?

TFM = your Framework that you use. .NET 5.0, .NET 6.0, .NET-Framework 4.8.2?? I used a NuGet-Package for my example.

You can use a VB.NET to C# Converter like https://converter.telerik.com/

DarthVader85PA commented 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;

public class TestForm
{
    public TestForm()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // Bind DataTable to Grid
        this.dgvTest.DataSource = this.GetDataTable();
    }

    private DataTable GetDataTable()
    {
        // Create DataTable
        DataTable dtTest = new DataTable("Test");

        // Add Columns
        dtTest.Columns.AddRange(new DataColumn[] {
            new DataColumn("colID", typeof(int)) { AllowDBNull = false, Caption = "ID" },
            new DataColumn("colDesc", typeof(string)) { AllowDBNull = false, Caption = "Description" }
        });

        // Add Example-Rows
        dtTest.Rows.Add(1, "First Row");
        dtTest.Rows.Add(2, "Second Row");
        dtTest.Rows.Add(3, "Thirth Row");
        dtTest.Rows.Add(4, "Fourth Row");

        // Return DataTable
        return dtTest;
    }
}
criss02-cs commented 2 years ago

Hi, users.ToDataTable() is a extension method that I have created to parse a list to a DataTable. The parsing from json is working perfectly. I use net 5.0

criss02-cs commented 2 years ago

public static DataTable ToDataTable(this IList data) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); foreach (PropertyDescriptor prop in properties) table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); foreach (T item in data) { DataRow row = table.NewRow(); foreach (PropertyDescriptor prop in properties) row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; table.Rows.Add(row); } return table; } This is the code that I use for this extension method

dax-leo commented 2 years ago

Hi, I replicated your case and everything works fine. Not sure what is your User class structure or how many rows of data you have but for a small simple example it worked just fine. It could be your User class has some weird property which is in conflict with gridview column property or something similar. In any case I don't see any problem here related to Krypton GridView.

I think this issue can be closed.

PWagner1 commented 2 years ago

Hi @criss02-cs is it possible that the extension method gets stuck in a loop when handling large amounts of data, or a memory leak?

criss02-cs commented 2 years ago

Hi @criss02-cs is it possible that the extension method gets stuck in a loop when handling large amounts of data, or a memory leak?

HI, I don't think it's that because I tested with only 2 rows

criss02-cs commented 2 years ago

I tried to use a normal datagrid and I works fine

PWagner1 commented 2 years ago

Hi @criss02-cs is it possible to provide a video? I've ran your example and it seems to work.

criss02-cs commented 2 years ago

Hi @criss02-cs is it possible to provide a video? I've ran your example and it seems to work.

Sorry I can't send a video right now. I will send it as fast as I can

criss02-cs commented 2 years ago

Hi, I have already tested and it's works fine, I don't know how but it works