XML Sql Server Attribute in datagridView Columns or details view RRS feed

  • Question

  • hy guys,

    i have a Bill table that contains multiple Data Type of sql server and an xml field that store a table of VAT and i want to bind it to the datagridview like in the picture.

    public FrmBillsList() { InitializeComponent(); dgvBillList.AutoGenerateColumns = false; addVTAColumns(); List<Bill> liste = Locator.Instance.BillSrvices.LoadAll();

    dgvBillList.DataSource = liste;



    private void addVTAColumns() {

    //this method to add VTAs Columns for the datagridView from a table that contains the list of VTAs dgvBillList.VirtualMode = true; VTAList = Locator.Instance.VTAServices.LoadAll(); foreach (VTA item in VTAList) { DataGridViewTextBoxColumn dgvc = new DataGridViewTextBoxColumn(); dgvc.HeaderText = "VTA " + item.Rate.ToString(); dgvBillList.Columns.Add(dgvc); } }

    private void LoadVTA()
                int l = dgvBillList.Columns.Count;
                int x = 0;
                foreach (Bill item in liste)
                    if (item.VTAS != null)
                            XDocument Bases = XDocument.Parse(item.VTAS);
                            foreach (var Base in Bases.Element("Bases").Elements())
                                dgvBillList.Rows[x].Cells[Base.FirstAttribute.toString()].Value = Base.LastAttribute.Value.ToString();
                        catch (Exception)

      <Base Rate="18.00" Sum="13.968" />

     <Base Rate="22.50"  Sum="16.943" />


    I try it with OnCellFormating event (because of mixed mode, bound and unbound) but it's so so heavy in loading datagridview.

    Note: XML Lines can varies from a Bill to other.
    any ine has an idea and excuse me for this strange thread :)

    Thanks in advance.

    Sunday, April 8, 2012 6:47 AM

All replies

  • So what really is your question? Sorry, but you didnt write one. I can see you:

    - create columns to dgv

    - bind some data to dgv

    - add additional data to some rows

    So what you like to do?


    Sunday, April 8, 2012 8:39 AM
  • Hi MNIF,
    I have a same question with Mitja. What’s the issue?
    As there are lots of custom class and method in your code, it is hard to detect the problem.
    Could you please kindly elaborate your question?
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 11, 2012 7:14 AM