DataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True
어떻게 DataGridView에 공백 (vb.net/C#)
설정 한
없이 텍스트를 감싸는 그러나이 WrapMode
공백없이 단일 단어로 열을 포장하지 않습니다. WrapMode
과 함께 "깰 수있는"방법이 있습니까? 아니면 다른 해결책?
DataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True
어떻게 DataGridView에 공백 (vb.net/C#)
설정 한
없이 텍스트를 감싸는 그러나이 WrapMode
공백없이 단일 단어로 열을 포장하지 않습니다. WrapMode
과 함께 "깰 수있는"방법이 있습니까? 아니면 다른 해결책?
CellPainting
이벤트로 재생할 수 있습니다.
DrawString
은 바운딩 Rectangle
을 존중하며 오른쪽 경계에 도달 할 때마다 줄 바꿈합니다.
설정 한도를 초과하는 셀에만 적용되도록 조건의 주석 처리를 제거 할 수 있습니다. 최상의 제어를 위해 정확한 한계를 알아 내기 위해 FormattedValue
의 길이를 측정해야합니다.
셀에 특수 정렬이있는 경우 그리기 위치를 미세 조정할 수도 있습니다.
private void DGV1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.Value == null) return;
if (e.FormattedValue.GetType() != typeof(System.String)) return;
bool selected = (e.State & DataGridViewElementStates.Selected)
== DataGridViewElementStates.Selected;
string s = e.FormattedValue.ToString();
//if (s.Length > 20) // Apply to all or only those breaking your limits
{
e.PaintBackground(e.CellBounds, selected);
e.Graphics.DrawString(s, DGV1.Font, selected ?
SystemBrushes.HighlightText : SystemBrushes.ControlText,
new Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 2,
e.CellBounds.Width - 2, e.CellBounds.Height - 4));
e.Handled = true;
}
}
설정은 Row.Heights
까지입니다. FormattedValue
측정을 위해 가면 RectangleF
을 얻을 수 있습니다. 따라서 Cell
에 대해 필요한 Height
을 알 수 있습니다. 현재의 Row.Height
과 비교하면 점차적으로 각 에 맞게 조정할 수 있습니다. 즉, 필요할 때마다 커지게하십시오. 높이가 다른 행이 생기고 원치 않는/불필요한 행을 가져올 수 있기 때문에 포함하지 않았습니다. 케이스. 당신이 관심이 있다면, 나는 하이 Shimply hown로 할 것이다 속성 창에서
출력을
DGLogs.Columns[0].DefaultCellStyle.WrapMode=DataGridViewTriState.True;
set
AutosizecolumnMode=AllCells
AutosizeRowMode=AllCells
를 바인딩 한 후 행 다음에 추가
나는 똑같은 문제에 직면 해있다! 아직 해결책이 없습니다! –
문제를 해결 했습니까? – TaW
늦게 답변을 드려 죄송합니다. DataGridView를 사용하지 않게되었습니다. 우리는 인쇄 기능, 요약 기능, 필터, 내장 검색 등과 같은 더 많은 이유로 유료 그리드를 사용하고 있습니다. – nitika