当我将鼠标悬停在datagridview控件(dgrv1)上的列标题上时,我想显示工具提示。目前,我可以执行以下操作,但是 - 我的datagridview有几列(每个工具提示有很多文本),所以我想从mousehover事件中调用一个方法。我的问题是我不知道如何捕获我悬停在哪个列上传入方法。有趣的是,mousehover事件在我当前的场景中选择了正确的列:
private void dgrv1_MouseHover(object sender, EventArgs e)
{
dgrv1.Columns[1].ToolTipText = "column 1";
dgrv1.Columns[2].ToolTipText = "column 2";
dgrv1.Columns[3].ToolTipText = "column 3";
}
如果我将鼠标悬停在第1列上 - 第1列的工具提示显示,第2列,第3列相同......但不是列出50列(工具提示将包含相当多的文本)这里的mousehover事件,我怎样才能从mousehover事件中调用一个方法并传入正确的列号?
答案 0 :(得分:1)
使用DataGridViewCellEventArgs:
执行此操作private void DataGridView_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
e.ColumnIndex //column
e.RowIndex //row
}
答案 1 :(得分:1)
您不需要在悬停事件中指定列的ToolTipText
属性。您只需使用Designer
分配它们,或者如果您希望在使用此类代码加载数据或加载表单事件时分配它们:
foreach (DataGridViewColumn c in this.dataGridView1.Columns)
{
c.ToolTipText = string.Format("Column {0}", c.Index + 1);
}
您还可以为单元格的ToolTip
属性分配文本:
this.dataGridView1.Rows[0].Cells[0].ToolTipText = "Some text"
但是如果你想知道鼠标悬停在它上面的列和行是什么,你可以使用DataGridView
的{{3}}方法:
private void dataGridView1_MouseHover(object sender, EventArgs e)
{
var p = this.dataGridView1.PointToClient(Cursor.Position);
var info = this.dataGridView1.HitTest(p.X, p.Y);
//You can use this values
//info.ColumnX
//info.RowY
//info.ColumnIndex
//info.RowIndex
}
注意列标题单元格的RowIndex
为-1,行标题单元格的ColumnIndex
为-1。
答案 2 :(得分:0)
试试这个:
Dim grvScreenLocation As Point = DGVRejected999Clm.PointToScreen(DGVRejected999Clm.Location)
Dim tempX As Integer = DataGridView.MousePosition.X - grvScreenLocation.X + DGVRejected999Clm.Left
Dim tempY As Integer = DataGridView.MousePosition.Y - grvScreenLocation.Y + DGVRejected999Clm.Top
Dim hit As DataGridView.HitTestInfo = DGVRejected999Clm.HitTest(tempX, tempY)
cellX = hit.RowIndex
cellY = hit.ColumnIndex
Dim col =DGVRejected999Clm.Columns(cellY).Name
If col="INTERNAL_STATUS" THEN
Dim value =DGVRejected999Clm.Rows(cellX).Cells(cellY).Value.ToString
If Value="E" THEN
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="999 ERROR"
Else If Value="F" Then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="EJECTED BY EDI SIMPLIFIED"
Else If value="N" Then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="NEW CLAIM"
Else If value="R" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="REGENERATED- WAITING FOR SUBMISSION"
Else If value="S" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="SUBMITTED"
Else If value="K" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="999 ACKNOWLEDGED"
Else If value="D" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="999 DENIED. RESUBMISSION REQUIRED"
Else If value="A" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="277 ACCEPTED"
Else If value="J" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="277 REJECTED"
Else If value="Q" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="REQUEUED"
Else If value="M" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="SEND TO PM-REJECTED by Payer"
Else If value="X" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="SEND TO PM-REJECTED by EDI Simplified"
Else If value="T" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="999 ACKNOWLEDGED-Payer dont support 277 - Payer Accepted"
Else If value="V" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="999 ACKNOWLEDGED-Payer dont support 277 - Payer Rejected"
Else If value="G" then
DGVRejected999Clm.Rows(cellX).Cells(cellY).ToolTipText="Rejected Claim - Review Required"
End If
End If