Search code examples
avaloniaui

Avalonia DataGrid and object[] how to tie


There is

public object[]? obj;
public ObservableCollection<object>datatablew { get; set; }
public diztablew(object grps)
{
    datatablew = new ObservableCollection<object>() { grps };
    obj = new object[3];
    obj[0] = "1111";
    datatablew.Add(obj);
}
 how to tie
 <DataGridTextColumn Header="id" Binding="{Binding Path=?????}"/>

is it possible ? class grps not available at this location .


Solution

  • I solved part of the problem like this

    public void init(object grps, Microsoft.Data.SqlClient.SqlConnection conns)
            {
                var testAssembly = Assembly.LoadFrom(grps.GetType().Assembly.FullName?.Split(",")[0] + ".dll");
                var t = testAssembly.GetType(grps.GetType().FullName);
                datatablew = new ObservableCollection<object>();
                string cluc = "select top 10 kod_rel,uet,rtrim(name) as name from statistika.dbo.statpra";
                var comms = new Microsoft.Data.SqlClient.SqlCommand(cluc, conns);
                var readers = comms.ExecuteReader();
                var counts = readers.FieldCount;
                while (readers.Read() == true)
                {
                    var ooo = Activator.CreateInstance(t);
                    for (int i = 0; i < counts; i++)
                    {
                        var obbjj = readers.GetValue(i);
                        try
                        {
                            var pps = grps.GetType().GetProperty(readers.GetName(i));
                            pps.SetValue(ooo,obbjj,null); 
                        }
                        catch { }
                    }
                    datatablew.Add(ooo);
                }
                readers.Close();
            }    
    it remains to be decided
    <DataGridTextColumn Header="kod_rel" Binding="{Binding ????,StringFormat=0;-0;#}"/>
    `, how to bind kod_rel which is in ObservableCollection<object> , if I bet ```AutoGenerateColumns="true"``` 
    then everything works as it should, but I need to define the columns myself .`