日期:2014-05-17  浏览次数:21014 次

DataGrid内容显示问题
C#的 DataGrid 如何去实现 超出文本字数,用...表示,鼠标悬停显示全部内容?
datagrid c#

------解决方案--------------------
只要单元格不自动换行,超过会自动显示省略号,这时候可以在以下事件中做处理:

 private void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                {
                    e.ToolTipText = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                }
            }
        }