[英]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.