简体   繁体   English

如何将单击事件设置为行中的所有单元格? Gridview Winforms Devexpress

[英]How to set click Event to all cells in a Row ? Gridview Winforms Devexpress

I have Gridview and I want to set click Event on the all cells in a Row ? 我有Gridview,我想在行的所有单元格上设置单击事件吗? How to Complete my Task ?? 如何完成我的任务?

I tried this code but when i double click on the cell the new Form will come in Back / Behind of current Form. 我尝试了这段代码,但是当我双击该单元格时,新表单将出现在当前表单的“后退” /“后​​面”。 How to Show it on the Front ? 如何在正面显示它?

 private void gridView2_DoubleClick(object sender, EventArgs e)
    {
        GridHitInfo celclick = gridView2.CalcHitInfo(gridControl2.PointToClient(Control.MousePosition));

        if (celclick.InRow)
        {

        }
    }

Please help me. 请帮我。

I have no Visual Studio here to test it but i think it should be something like this: 我这里没有Visual Studio进行测试,但我认为应该是这样的:

 foreach(GridViewRow row in gridView2.Rows)
 {
       //Here you need something to get the cells out of row
       cell.Click += (s, e) => { myClickEvent(c); };
 }

Good luck 祝好运

EDIT: Try this: 编辑:试试这个:

 foreach(GridViewRow row in gridView2.Rows)
 {
     foreach (DataControlFieldCell cell in row.Cells)
     {
         cell.Click += (s, e) => { myClickEvent(c); };
     }
 }

Use the GridView.RowCellClick event as follows: 使用GridView.RowCellClick事件,如下所示:

gridControl1.DataSource = new List<Person> { 
    new Person(){ Name="John Smith"},
    new Person(){ Name="Mary Smith"}
};
gridView1.OptionsBehavior.Editable = false; // disable editing
gridView1.RowCellClick += gridView1_RowCellClick;
//...
void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) {
    if(e.Clicks == 2) { // Double Click
        object cellValue = e.CellValue;
        //do some stuff
    }
}
//...
class Person {
    public string Name { get; set; }
}

Here is the solution: 解决方法如下:

DataTable dt = new DataTable();
    private void B_Click(object sender, EventArgs e)
    {

        Button bt = (Button)sender;
        int productId = (int)bt.Tag;
        AddProductDataContext db = new AddProductDataContext();
        decimal Quantity;
        decimal.TryParse(txtCalculator.Text, out Quantity);
        var results = from inv in db.Inventories
                      where inv.RecId == productId
                      select new
                      {
                          inventoryName = inv.InventoryName,
                          Quantity,
                          Total = Quantity * inv.InventoryPrice
                      };





        foreach (var x in results)
        {
            DataRow newRow = dt.NewRow();
            newRow.SetField("inventoryName", x.inventoryName);
            newRow.SetField("Quantity", x.Quantity);

            newRow.SetField("Total", x.Total);
            dt.Rows.Add(newRow);



        }


        gridControl1.DataSource = dt;


    }              
    private void SaleScreen_Load(object sender, EventArgs e)
    {

        dt.Columns.Add("inventoryName");
        dt.Columns.Add("Quantity");
        dt.Columns.Add("Total");

    }

I solved the problem in this way. 我以这种方式解决了问题。 Thanks to everybody for their precious helps. 感谢大家的宝贵帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在单击时突出显示DevExpress gridview中的焦点行? - How to highlight focused row in DevExpress gridview on click? 如何在EditValue中设置GridView的筛选器已更改? Winforms Devexpress - How to set filter for GridView in EditValue changed ? Winforms Devexpress 如何在运行时设置过滤器? 用于C#,Winforms,DevExpress中的gridview - How to set Filter in run time ? for gridview in C#, Winforms, DevExpress 有没有一种方法可以自动格式化DevExpress GridView Winforms中的行? - Is there a way to to autoformat a row in DevExpress GridView winforms? 如何通过单击按钮从DataTable在DevExpress Gridview中添加新行 - How to add new Row in DevExpress Gridview from DataTable on Button Click 如何从Gridview中的上一行到当前行获取特定单元格值? Winforms Devexpress - How to get Particular cell value from Previous row to Current Row in Gridview ?? Winforms Devexpress 如何使用 Winforms 中的 C# 代码在 DevExpress Gridview 中添加新行? - How to add new row in DevExpress Gridview using C# code in Winforms? 如何从Access数据库获取值并在C#winforms Devexpress中的Gridview中进行设置? - How to get the values from Access Database and set in Gridview in C# winforms Devexpress? 单击gridview中单个单元格的事件 - click event for a individual cells in gridview 如何取消选择devexpress网格中的行 - winforms - How deselect row in grid of devexpress - winforms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM