c#devexpress gridview row collect

时间:2015-06-30 00:36:36

标签: c# gridview devexpress row

c#devexpress gridview选择行计数错误 我想从另一个表格(gridcontrol)获取行,我尝试了form.gridview.selected.row.count但它不起作用。得到这个数字我能写些什么?从其他形式的钱,我想打印标签来收集这个表格。 ""

gridView1.Columns["money"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            gridView1.Columns["money"].SummaryItem.DisplayFormat = "Toplam:{0:n2}";
            gridView1.OptionsView.ShowFooter = true;

"" 我尝试这个代码工作但在gridview但我想在标签中写其他形式。

2 个答案:

答案 0 :(得分:1)

form1有gridView1。

form2有label2。 label2显示来自gridView1的总和。

form1必须将form2作为其字段或属性。

form2必须有方法public void SetSum(money sum)才能为label2设置总和。

每个计数总和(例如通过点击按钮)调用form2.SetSum(sum)

MainForm.cs - 主机form1和form2

public partial class MainForm : Form
{
    private Form1 _form1;

    private Form2 _form2;

    public MainForm()
    {
        InitializeComponent();
        _form2 = new Form2();
        _form1 = new Form1(_form2);
    }

    private void btnForm1_Click(object sender, EventArgs e)
    {
        _form1.Show(this);
    }

    private void btnForm2_Click(object sender, EventArgs e)
    {
        _form2.Show(this);
    }
}

Form1.cs的

public partial class Form1 : Form
{
    private Form2 _receivedForm;

    public Form1()
    {
        InitializeComponent();
    }

    public Form1(Form2 receivedForm) : this()
    {
        _receivedForm = receivedForm;
    }

    private void btnSend_Click(object sender, EventArgs e)
    {
        _receivedForm.SetSum(txtSum.Text);
    }
}

Form2.cs:

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    public void SetSum(string sum)
    {
        lblSum.Text = sum;
    }
}

enter image description here 希望这有帮助。 :d

答案 1 :(得分:0)

ı确实使用此代码现在正在工作。谢谢你的回答

DataBaseDataContext db = new DataBaseDataContext();
       var sum = (from ord in db.safes select ord.money).Sum();
                lbl_safein.Text = sum.ToString();