Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2490
WinGrid Add property of entity child
posted

Hi,

Is it possible to add column of my grid of entity child ?

Entity Quote.Customer

I want to add column  Customer.Name of my band.

At the moment I add property of my Entity, but I want to know if is have other way.

public string CustomerName
{
get
{
if (Customer == null)
return string.Empty;
else
return Customer.Name;
}
}

Francois

  • 7695
    Offline posted

    Hi Francois,

        Two ways come to mind. First, you could modify your Customer object's ToString() method to return Customer.Name. This would have the effect of showing the Customer's Name in place of the Customer object.

    If you would rather not modify your Customer.ToString() method, the next method would be to add an unbound column in the InitializeLayout method, and set the value in the InitializeRow method, below is a quick snippet.

            private void UltraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                // Adding unbound column, the if check is incase of rebinding, you do not add it twice
                if (!e.Layout.Bands["Quote"].Columns.Exists("custName"))
                {
                    var colCustName = e.Layout.Bands["Quote"].Columns.Add("custName");
                    colCustName.Header.Caption = "Customer";
                }

                //Hide the base customer column
                e.Layout.Bands[0].Columns["Customer"].Hidden = true;
            }

            private void UltraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                var customer = e.Row.Cells["Customer"].Value as Customer;
                e.Row.Cells["custName"].Value = customer.Name;
            }

    Let me know if that helps with what you are looking for,