DevExpress C# grid view doesn't display data

82 Views Asked by At

I want to display some data in the gridView1 from a list but it won't show the data just the header row. I created a datasource object Transakcija and selected it as a data source for the gridControl but it just doesn't display the actual data.

private void Form1_Load(object sender, EventArgs e)
{
        List<Transakcija> list1 = new List<Transakcija>();
        
        list1.Add(new Transakcija
        {
            TrnType = "1",
            IzvodBroj = "2",
            NovoStanje = "3",
            PrethodnoStanje = "4",
            FitID = "5",
            TrnUID = "6",
            Benefit = "7",
            NazivPrimaoca = "8",
            Grad = "9",
            Racun = "10",
            BankID = "11",
            Banka = "12",
            Datum = "13",
            Iznos = "14",
            SvrhaPlacanja = "15",
            Sifra = "16",
            Valuta = "17",
            PayeeRefNumber = "18",
            TrnPlace = "19",
            DtUser = "20",
            DtAvail = "21",
            RefNumber = "22",
            RefModel = "23",
            PayeeRefModel = "24",
            Urgency = "25",
            Naknada = "26",
            StatusCode = "27",
            StatusTimePosted = "28",
            RacunBanke = "29"
        });

        gridControl1.DataSource = new System.ComponentModel.BindingList<Transakcija>(list1);
        gridControl1.Refresh();

}

I tried looking at the properties of the grid control but I didn't find why it doesn't display it.

2

There are 2 best solutions below

1
JayV On

After some investigation I have a potential solution for you (its a best guess as you haven't provided the definition of the class Transakcija or shown how the columns are defined or added to the GridControl/GridView).

There are also other considerations such as setting the FieldName of the GridColumn.

I found that it depends on how your class Transakcija is defined.

If the members TrnType, IzvodBroj, NovoStanje, etc are defined as Fields then it won't work. They need to be defined as Properties.

This does not work

internal class Transakcija
{
    public String TrnType;
    public String IzvodBroj;
    public String NovoStanje;
}

This does work:

internal class Transakcija
{
    public String TrnType { get; set; }
    public String IzvodBroj { get; set; }
    public String NovoStanje { get; set; }
}
0
Tihomir Raicevic On

I found the issue the code was ok but I had to reselect the data source object again in the GUI part probably was an old object before rebuilding the project.