This is a migrated thread and some comments may be shown as answers.

Binding Grid (with childrow) to Databinding

3 Answers 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
DenisCL
Top achievements
Rank 1
DenisCL asked on 28 Apr 2011, 09:52 AM
Hello,

I'm actually using a databinding, which has a DataTable as Datasource.

DataTable dataTable = new DataTable();
dataTable.Columns.AddRange(new DataColumn[]{
        new DataColumn("NumeroActe", typeof(string)), 
        new DataColumn("DateActe", typeof(string)), 
        new DataColumn("TypeBien", typeof(string)), 
        new DataColumn("Surface", typeof(decimal)), 
        new DataColumn("Prix", typeof(decimal)), 
        new DataColumn("Pieces", typeof(int)), 
        new DataColumn("EpoqueConstruction", typeof(string)),
        new DataColumn("NumeroRue", typeof(string)),
        new DataColumn("NomRue", typeof(string)),
        new DataColumn("LieuDit", typeof(string)),
        new DataColumn("CodePostal", typeof(string)),
        new DataColumn("Localite", typeof(string)),
        new DataColumn("Maison", typeof(bool)), 
        new DataColumn("Appartement", typeof(bool)), 
        new DataColumn("Terrain", typeof(bool)), 
        new DataColumn("Local", typeof(bool)), 
        new DataColumn("Annexe", typeof(bool)), 
        new DataColumn("Cave", typeof(bool)), 
        new DataColumn("Garage", typeof(bool)),
        new DataColumn("Grenier", typeof(bool))
    });
 
dataTable.BeginLoadData();
 
foreach (DataRow row in table.Rows)
{
    // Create a ExportVenteData according to the current Database row
    ExportVenteManager manager = new ExportVenteManager();
    ExportVenteData tmpExportData = manager.BuildExportVenteData(row);
 
    if (tmpExportData != null && tmpExportData.IsValid())
    {
        // Create the new custom line for the datasource
        DataRow ligne = dataTable.NewRow();
 
        ligne["NumeroActe"] = tmpExportData.NumActe;
        ligne["DateActe"] = tmpExportData.DateActe.ToString("dd/MM/yyyy");
        ligne["TypeBien"] = cTypeFiche.GetLibelle(tmpExportData.TypeBien);
        ligne["Prix"] = tmpExportData.PrixVente;
        ligne["Surface"] = tmpExportData.Surface;
        ligne["Pieces"] = tmpExportData.NbPieces;
        ligne["EpoqueConstruction"] = cLibellesEnums.EpoqueConstruction.ToString(tmpExportData.EpoqueConstruction);
 
        ligne["NumeroRue"] = row["NUMERO_RUE"] != null ? row["NUMERO_RUE"].ToString() : "";
        ligne["NomRue"] = row["NOM_RUE"] != null ? row["NOM_RUE"].ToString() : "";
        ligne["LieuDit"] = row["LIEU_DIT"] != null ? row["LIEU_DIT"].ToString() : "";
        ligne["CodePostal"] = row["CODE_POSTAL"] != null ? row["CODE_POSTAL"].ToString() : "";
        ligne["Localite"] = row["LOCALITE"] != null ? row["LOCALITE"].ToString() : "";
 
        foreach (eTypeFiche fiche in tmpExportData.LstAnnexesSupplementaires)
        {
            switch (fiche)
            {
                case eTypeFiche.ANNEXE:
                    ligne["Annexe"] = true;
                    break;
                case eTypeFiche.ANNEXE_CAVE:
                    ligne["Cave"] = true;
                    break;
                case eTypeFiche.ANNEXE_GRENIER:
                    ligne["Grenier"] = true;
                    break;
                case eTypeFiche.APPARTEMENT:
                    ligne["Appartement"] = true;
                    break;
                case eTypeFiche.GARAGE:
                    ligne["Garage"] = true;
                    break;
                case eTypeFiche.LOCAL:
                    ligne["Local"] = true;
                    break;
                case eTypeFiche.MAISON:
                    ligne["Maison"] = true;
                    break;
                case eTypeFiche.TERRAIN:
                    ligne["Terrain"] = true;
                    break;
            }
        }
 
        dataTable.Rows.Add(ligne);
    }
}
 
dataTable.EndLoadData();

This DataTable is a custom version of SQLServer database format, and suit with my grid (every column is link by name with my databinding columns)

dgvData.MasterTemplate.BeginUpdate();
bdsData.DataSource = _dataTable;
dgvData.MasterTemplate.EndUpdate();


My grid has my databinding as datasource.
Actually everything is fine. (see screen1.png attached)
As you can see in screen1.png, there are some checkboxcolumns in my grid, and I would like to move theses columns to a childrow. (screen2.png)

Is there a way to do this programmatically?
I could already add chilrows


Second point:
Since I use the databinding, I can't interfere anymore on the cellformatting event in order to put my datevalue "01/01/0001" to string.empty.
Any solution as wordaround?

Thanks for your lights

Regards

Thanks a lot

3 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 29 Apr 2011, 12:15 PM
Hello Denis,

For the second point, you could think about using nullable dates (DateTime?) and when you have a null date, it will show up as blank.

Your first issue is a tad more complex, you should take a look at this help article: Binding to Hierarchical Data or Tutorial: Binding to Hierarchical Data or Binding to Hierarchical Data Automatically or Binding to Hierarchical Data Programmatically.

If you still have problems please let me know and i will try to provide an example.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP


0
DenisCL
Top achievements
Rank 1
answered on 03 May 2011, 03:20 PM
Hello

it's a bit difficult to find how doing.
I actually have my childrow added for each row.

Do you simply know how feeling a cell value of the childrow manually?

A simple way to access to it? something like myDatagridview.Rows[0].ChildRow[0].Cells[0].Value?

Thanks

Regards

0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 03 May 2011, 06:58 PM
Hello again,

Yes, you are correct in the way to access child rows, but you should also check if there are any child rows before actually accessing data, like so:
if (radGridView1.Rows[0].HasChildRows())
{
    var value = radGridView1.Rows[0].ChildRows[0].Cells[0].Value;
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
DenisCL
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
DenisCL
Top achievements
Rank 1
Share this question
or