'C# dataGridView 셀 툴팁'에 해당되는 글 1건

728x90

dataGridView cell 에 툴팁이 보이게 하는 걸 알고 싶어 테스트를 해봤다.

두가지 모두 정상적으로 잘 동작되었다.


방법 1

private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
    dataGridView1.CellToolTipTextNeeded += new DataGridViewCellToolTipTextNeededEventHandler(dataGridView1_CellToolTipTextNeeded);
}

void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
{
    if (e.ColumnIndex == this.dataGridView1.Columns["Price"].Index)
    {
        e.ToolTipText = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
    }
}


방법2
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if ((e.ColumnIndex == this.dataGridView1.Columns["Price"].Index) && e.Value != null)
    {
        DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        cell.ToolTipText = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
    }
}


일반적인 툴팁 사용은

MouseHover 이벤트를 발생시켜 보여주고 싶은 메시지를 보여주면 된다.

private void expandSearch_MouseHover(object sender, EventArgs e)
{

    toolTip1.IsBalloon = true;  // 풍선도움말 모양으로

    toolTip1.SetToolTip(expandSearch, "전체 DB 대상 검색");
}


툴팁은 0.5초 후에 나타나고 5초뒤에 사라지는 것이 기본이다.

프로그램이 Load 될 때에 보여주고 싶은 툴팁을 지정해줘도 된다.


블로그 이미지

Link2Me

,