[在线等]winfrom中DataGridView的MouseEnter事件如何定位cell

时间:2022-10-01 16:23:32
DataGridView的MouseEnter事件如何定位进入了那个cell?
恳请高手解答

12 个解决方案

#1


该回复于2010-12-02 16:07:13被版主删除

#2


没明白

圈里头的cell永远够不着

#3


该回复于2010-11-12 14:51:51被版主删除

#4


回复:FoxDave
我的意思是datagridview 换单元格会触发此事件.我想知道他进入了那个单元格.

#5


顶顶很健康

#6


该回复于2010-11-12 15:30:48被版主删除

#7


currentrow能用吗?

#8


//这个是定位那一列
this.xfdgCode_DefRuleDtl.Columns[e.ColumnIndex].Name.ToString().Equals("ItemLenght")
//这个是定位那4行的那一列的值
this.xfdgCode_DefRuleDtl[4, e.RowIndex].Value.Equals("流水码")
看看应该明白吧!

#9


MouseEnter事件只在鼠标穿越DataGridView的边界时才发生,确切的说是即将进入时,所以在这个事件发生时鼠标哪个Cell也不位于!!!!

#10


 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MySuperMap
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            supermap1.Connect(superworkspace1.CtlHandle);//建立supermap与superworkspace之间的关系
            string strAlias;//数据源名称
            SuperMapLib.seEngineType nEngineType;//数据引擎类型
            string strDataSourceName;//数据源绝对路径名
            SuperMapLib.soDataSource objDataSource;//数据源对象,指向打开的数据源
            bool bReadOnly;//数据源里的数据是不是只读
            bool bAddToHead;//是否加到最上边
            int i;//循环变量
            strAlias = "MyDataSource";
            nEngineType = SuperMapLib.seEngineType.sceSDBPlus;

            strDataSourceName = @"D:\project\MySuperMap\World.sdb";
            bReadOnly = false;// 不设为只读
            //打开数据源
            objDataSource = superworkspace1.OpenDataSource(strDataSourceName,strAlias,nEngineType,bReadOnly);
            MessageBox.Show(objDataSource.Name);
            if (objDataSource == null)
            {
                MessageBox.Show("sorry!");
                return;
            }
            else
            {
                for ( i = 0; i < objDataSource.Datasets.Count; i++)
                {
                    bAddToHead = true;
                    supermap1.Layers.AddDataset(objDataSource.Datasets[i],bAddToHead);
                }
            }
            supermap1.Refresh();
            //修改选中对象风格
            supermap1.selection.Style.PenColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(231, 77, 0)));
            supermap1.selection.Style.PenWidth = 1;
            supermap1.selection.Style.PenStyle = 1;
            supermap1.selection.Style.BrushStyle = 5;
            supermap1.selection.Style.BrushColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(115, 69, 140)));
            supermap1.selection.Style.BrushBackColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(239, 150, 255)));
            supermap1.selection.Style.BrushOpaqueRate = 50; 
            System.Runtime.InteropServices.Marshal.ReleaseComObject(objDataSource); 
            objDataSource = null;
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            supermap1.Close();
            supermap1.Disconnect(); 
            superworkspace1.Close();
        }
    }
}

#11


你一定要在DataGridView的MouseEnter来判断Cell吗,其实你可以用DataGridView的CellMouseEnter事件,事件参数DataGridViewCellEventArgs可以获得进入单元格的所在行及列的索引值,大致代码如下:
        private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCell enterCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        }

#12


我用 CellEndEdit

#1


该回复于2010-12-02 16:07:13被版主删除

#2


没明白

圈里头的cell永远够不着

#3


该回复于2010-11-12 14:51:51被版主删除

#4


回复:FoxDave
我的意思是datagridview 换单元格会触发此事件.我想知道他进入了那个单元格.

#5


顶顶很健康

#6


该回复于2010-11-12 15:30:48被版主删除

#7


currentrow能用吗?

#8


//这个是定位那一列
this.xfdgCode_DefRuleDtl.Columns[e.ColumnIndex].Name.ToString().Equals("ItemLenght")
//这个是定位那4行的那一列的值
this.xfdgCode_DefRuleDtl[4, e.RowIndex].Value.Equals("流水码")
看看应该明白吧!

#9


MouseEnter事件只在鼠标穿越DataGridView的边界时才发生,确切的说是即将进入时,所以在这个事件发生时鼠标哪个Cell也不位于!!!!

#10


 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MySuperMap
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            supermap1.Connect(superworkspace1.CtlHandle);//建立supermap与superworkspace之间的关系
            string strAlias;//数据源名称
            SuperMapLib.seEngineType nEngineType;//数据引擎类型
            string strDataSourceName;//数据源绝对路径名
            SuperMapLib.soDataSource objDataSource;//数据源对象,指向打开的数据源
            bool bReadOnly;//数据源里的数据是不是只读
            bool bAddToHead;//是否加到最上边
            int i;//循环变量
            strAlias = "MyDataSource";
            nEngineType = SuperMapLib.seEngineType.sceSDBPlus;

            strDataSourceName = @"D:\project\MySuperMap\World.sdb";
            bReadOnly = false;// 不设为只读
            //打开数据源
            objDataSource = superworkspace1.OpenDataSource(strDataSourceName,strAlias,nEngineType,bReadOnly);
            MessageBox.Show(objDataSource.Name);
            if (objDataSource == null)
            {
                MessageBox.Show("sorry!");
                return;
            }
            else
            {
                for ( i = 0; i < objDataSource.Datasets.Count; i++)
                {
                    bAddToHead = true;
                    supermap1.Layers.AddDataset(objDataSource.Datasets[i],bAddToHead);
                }
            }
            supermap1.Refresh();
            //修改选中对象风格
            supermap1.selection.Style.PenColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(231, 77, 0)));
            supermap1.selection.Style.PenWidth = 1;
            supermap1.selection.Style.PenStyle = 1;
            supermap1.selection.Style.BrushStyle = 5;
            supermap1.selection.Style.BrushColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(115, 69, 140)));
            supermap1.selection.Style.BrushBackColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(Color.FromArgb(239, 150, 255)));
            supermap1.selection.Style.BrushOpaqueRate = 50; 
            System.Runtime.InteropServices.Marshal.ReleaseComObject(objDataSource); 
            objDataSource = null;
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            supermap1.Close();
            supermap1.Disconnect(); 
            superworkspace1.Close();
        }
    }
}

#11


你一定要在DataGridView的MouseEnter来判断Cell吗,其实你可以用DataGridView的CellMouseEnter事件,事件参数DataGridViewCellEventArgs可以获得进入单元格的所在行及列的索引值,大致代码如下:
        private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCell enterCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        }

#12


我用 CellEndEdit