0

i would like to create dynamically an unbound column in an Xtragrid control devexpress ; there is the scenario : i have a grid bound with data from Payment Datatable , fields are " Payment_ID , Customer_ID " so on and so forth , what i would like to do is , instead of having Customer_ID which is the foreign in this table , i want to have in it ,Customer_Name related to Customer_ID , to avoid confusion . someone Help Thanks(using winforms C#). below code used ; to populate the grid

          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Drawing;
          using System.Data;
          using System.Linq;
          using System.Text;
          using System.Windows.Forms;
          using System.Data.SqlClient;

          namespace YoungWoman
            {
               public partial class Payment2 : UserControl
                   {
                          DataSet ds3 = new DataSet();
                          SqlDataAdapter dapayment = new SqlDataAdapter();
                          SqlConnection conne = SqlCoonectionSEtup.GetConnection;
                          BindingSource PaymentBinding = new BindingSource();

               public Payment2()
                {
                   InitializeComponent();
                }

               private void AddPayment_Click(object sender, EventArgs e)
            {
               Paymentfrm payent = new Paymentfrm(Utils.Formtype.add, 0);
               payent.PaymentEvent += new EventHandler(RefreshingGrid);
               payent.PayentlabelsEvent += new EventHandler(RefresHlabels);

               payent.ShowDialog();

            }

               private void EditPayment_Click(object sender, EventArgs e)
              {
                 Paymentfrm pyt = new Paymentfrm(Utils.Formtype.edit, 1);
               pyt.ShowDialog();
              }
                   void RefreshingGrid(object sender, EventArgs e)
             {
                  ds3.Tables["tblPaymentYW"].Clear();
                  SqlCommand cmd = new SqlCommand("SELECT * FROM PaymentYW", conne);

                       dapayment.SelectCommand = cmd;
                        dapayment.Fill(ds3, "tblPaymentYW");
                        DgPaymentYW.DataSource = ds3.Tables["tblPaymentYW"];
                        DgPaymentYW.RefreshDataSource();
             }
    void RefresHlabels(object sender, EventArgs e)
    {
        LoadData();
    }


    private void Payment2_Load(object sender, EventArgs e)
    {
        LoadData();



    }

    private void LoadData()
    {
        SqlCommand cmd = new SqlCommand("SELECT *FROM PaymentYW ORDER BY PaymentId ", conne);
        dapayment.SelectCommand = cmd;
        ds3.Clear();
        dapayment.Fill(ds3, "tblPaymentYW");
        PaymentBinding.DataSource = ds3.Tables["tblPaymentYW"];
        DgPaymentYW.DataSource = PaymentBinding;

        this.PaymentIdlabelContro.DataBindings.Clear();
        this.PaymentIdlabelContro.DataBindings.Add(new Binding("Text", PaymentBinding, "PaymentId"));
        ReservationIdlabelControl.DataBindings.Clear();
        this.ReservationIdlabelControl.DataBindings.Add(new Binding("Text", PaymentBinding, "ReservationId"));
        LesseeIdlabelControl.DataBindings.Clear();
        this.LesseeIdlabelControl.DataBindings.Add(new Binding("Text", PaymentBinding, "LesseeId"));

        DatelabelControl.DataBindings.Clear();

        this.DatelabelControl.DataBindings.Add(new Binding("Text", PaymentBinding, "PaymentDate"));
        AmountlabelControl.DataBindings.Clear();
        this.AmountlabelControl.DataBindings.Add(new Binding("Text", PaymentBinding, "AmountPaid"));
        BalancelabelControl.DataBindings.Clear();
        this.BalancelabelControl.DataBindings.Add(new Binding("Text", PaymentBinding, "Balance"));
        gridView1.Columns[1].Visible = false;
        gridView1.Columns[6].Visible = false;


        DevExpress.Utils.FormatInfo fi = new DevExpress.Utils.FormatInfo();
        fi.FormatType = DevExpress.Utils.FormatType.Numeric;
        fi.FormatString = "c2";
        gridView1.Columns[5].DisplayFormat.Assign(fi);
        gridView1.Columns[4].DisplayFormat.Assign(fi);
        Rowcount();
        Priveleges();


    }

    void Rowcount()
    {
        RecordlabelControl.Text = " Records : " + (gridView1.RowCount);

    }
    void Priveleges()
    {
        if (SqlCoonectionSEtup.Priveleges == "User")
        {
            AddPayment.Enabled = false;
            EditPayment.Enabled = false;
            CancelBtn.Enabled = false;
        }
        else
        {

            AddPayment.Enabled = true;
            EditPayment.Enabled = true;
            CancelBtn.Enabled = true;

        }
    }

}

}

4

2 回答 2

1

在您的 Select 语句中,您能否将 PaymentYW 表与 customer_ID 字段上的 Customer 表连接起来?然后所有客户字段都将可用,您可以在 DataGrid 中包含 Customer_Name 列。

于 2012-08-15T15:22:56.160 回答
0

如果我的理解是正确的,您希望显示等效的 customer_name 来代替 customner_id。您可以通过使用RepositoryItemLookUpEdit来实现此行为。

首先将 repositoryItemLookUpEdit 作为列编辑器添加到使用“Customer_ID”映射的列

从客户表中获取客户信息并将其分配给 repositoryItemLookUpEdit 数据源。

"Select Customer_ID,Customer_Name from Customers"- 像这样您可以获得您的客户详细信息。

为 id(Customer_ID) 和 name(Customer_Name) 将两列添加到 repositoryItemLookUpEdit,并为它们提供适当的字段名称。将“Customer_ID”字段作为值成员,将“Customer_name”字段作为显示成员分配给 repositoryItemLookUpEdit。这将满足您的要求。

为了获得更好的展示效果,您可以在 repositoryItemLookUpEdit 中将 id 列的可见性设为 false。

于 2012-08-22T06:58:07.197 回答