简体   繁体   中英

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 ? 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:

 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM