---------单元格编辑事件,用户编辑单元格后,执行操作-------------------
namespace testxxx
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
var sheet1 = reoGridControl1.CurrentWorksheet;
sheet1.SetRows(20);
sheet1.SetCols(20);
sheet1.Name = "M7M7M7M7M7";
sheet1.SetSettings(WorksheetSettings.View_ShowRowHeader, false);
sheet1.SetSettings(WorksheetSettings.View_ShowColumnHeader, false);
sheet1.SetSettings(WorksheetSettings.Edit_AllowAdjustRowHeight, false);
sheet1.SetSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth, false);
sheet1.CellEditTextChanging += OnCellEditTextChanging;
// Similarly, subscribe to CellEditCharInputted as needed
}
void OnCellEditTextChanging(object sender, CellEditTextChangingEventArgs e)
{
foot_txt.Text = e.Cell.Column.ToString();
}
}
}
---------右键点击表格,获取选中的单元格-------------------
public YourForm()
{
InitializeComponent();
// 添加MouseDown事件处理程序
reoGridControl1.MouseDown += ReoGridControl1_MouseDown;
}
private void ReoGridControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// 获取鼠标点击的位置
var pos = reoGridControl1.PointToClient(Cursor.Position);
// 获取选中的单元格
var cell = reoGridControl1.GetCellFromPoint(pos.X, pos.Y);
if (cell != null)
{
// 获取选中单元格的行号和列号
var row = cell.Row;
var col = cell.Column;
// 判断行号和列号的范围,决定是否执行右键弹出菜单
if (row >= 0 && row < 10 && col >= 0 && col < 10)
{
// 执行右键弹出菜单的逻辑
// ...
}
}
}
}