-1
all right ???
This is my first question here on stack overflow, I’m sorry if I did anything wrong !!!
I’m starting with C# and Devexpress and I’m trying to create an example using Devexpress Gridcontrol (v.19.2.5.0) with a class that contains some records in a List.
I created a simple project (Windows Forms) and put a Gridcontrol and tried to connect Gridcontrol to the class (Record.Cs / Prototipoviewmodel.Cs).
Gridcontrol in designer mode, lists the columns, but in run-time, it is empty.
Where did I go wrong ? Or what I didn’t do to list the records in run-time ?
My second question would be, can I insert, update and delete the run-time records directly in Gridcontrol using a list ?
Class Record.Cs
using System;
using System.Collections.Generic;
namespace Prototipo
{
Registro de classe pública
{
public DateTime? Dados {get; definir; }
public string Cliente {get; definir; }
public string Movimento {get; definir; }
Valor decimal público {get; definir; }
public static List <Record> GetRecords ()
{
Lista <Registro> pessoas = nova Lista <Registro> ();
people.Add (new Record () {Data = new DateTime (2021, 04, 07, 19, 00, 00), Cliente = "João", Movimento = "D", Valor = 1000});
people.Add (new Record () {Data = new DateTime (2021, 04, 07, 19, 30, 00), Cliente = "Maria", Movimento = "D", Valor = 2000});
people.Add (new Record () {Data = new DateTime (2021, 04, 07, 20, 00, 00), Cliente = "Jose", Movimento = "D", Valor = 3000});
retornar pessoas;
}
}
}
Class Prototypoviewmodel.Cs
using System.Collections.Generic;
namespace Prototipo
{
public class PrototipoViewModel
{
public PrototipoViewModel ()
{
this.Records = Record.GetRecords ();
}
Public List <Record> Records {get; definir; }
}
}
and Class frmPrototypMain.Cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
usando System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Prototipo
{
classe pública parcial frmPrototipoMain: DevExpress.XtraEditors.XtraForm
{
public frmPrototipoMain ()
{
InitializeComponent ();
}
}
}
The project is on Github (https://github.com/tiago-pimenta/vs_gridcontrol_bind_class)
Thank you
hello, I didn’t see in your question where does the bind of your data on the Grid
– Ricardo Pontual
@Ricardopunctual, in the "Data Sources" tab, I created one of the type "Object" and pointed to the class "Prototipoviewmodel" and in the property "Choose Datasource" of Grid, I selected "recordsBindingSource". It was just after this process that the columns appeared in design mode, but did not bring the data.
– tiago_pimenta
and you called him
DataBind()
right?– Ricardo Pontual
@Ricardopunctual no, the only codes really are the ones I put in, plus this configuration I ended up doing in Gridcontrol. I already used Devexpress in Delphi, there to popular the grid, we gave an "Open" in Dataset/Datasource, I believe that is missing a similar command, to give the "Get" in the records of the class Record.Cs, only I do not know how to do it.
– tiago_pimenta