How to set the DataGridViewCell to automatically wrap single long word?
Tag : chash , By : Nick Coats
Date : March 29 2020, 07:55 AM
To fix this issue This question is asked here many times but their answers are not working for me. , Use DataGridView CellPainting event. Sample code: public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
//dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
//dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
//dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[0].Value = "CELL123456789012345679801234567890";
row.Cells[1].Value = "CELL 1";
row.Cells[2].Value = "CELL 2";
row.Cells[3].Value = "CELL 3";
row.Cells[4].Value = "CELL 4";
row.Cells[5].Value = "CELL 5";
}
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.Value == null)
return;
var s = e.Graphics.MeasureString(e.Value.ToString(), dataGridView1.Font);
if (s.Width > dataGridView1.Columns[e.ColumnIndex].Width)
{
using (
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
e.Graphics.DrawString(e.Value.ToString(), dataGridView1.Font, Brushes.Black, e.CellBounds, StringFormat.GenericDefault);
dataGridView1.Rows[e.RowIndex].Height = (int)(s.Height * Math.Ceiling(s.Width / dataGridView1.Columns[e.ColumnIndex].Width));
e.Handled = true;
}
}
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.Value == null)
return;
var s = e.Graphics.MeasureString(e.Value.ToString(), dataGridView1.Font);
if (s.Width > dataGridView1.Columns[e.ColumnIndex].Width)
{
using (Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right, e.CellBounds.Bottom - 1);
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
e.Graphics.DrawString(e.Value.ToString(), dataGridView1.Font, Brushes.Black, e.CellBounds, StringFormat.GenericDefault);
dataGridView1.Rows[e.RowIndex].Height = (int)(s.Height * Math.Ceiling(s.Width / dataGridView1.Columns[e.ColumnIndex].Width));
e.Handled = true;
}
}
}
}
|
What rules/declarations do I need to add to a CSS class to enable word wrap with no single-word truncation?
Tag : html , By : user177837
Date : March 29 2020, 07:55 AM
To fix this issue I have a piece of html like this: , You can use JQuery: $(function () {
while ($('.category span').width() > $('.category').width()) {
$('.category span').css('font-size', (parseInt($('.category span').css('font-size')) - 1) + "px");
}
});
<div id="prizeCategory" class="category"><span>Applications</span></div>
|
Using word-wrap: break-word on two consecutive long words
Date : March 29 2020, 07:55 AM
wish of those help When using word-wrap: break-word on a div with two consecutive long words, the second word that is broken off starts on a new line, as such: .container{
width: 100px;
display: inline-block;
border: 1px solid black;
word-wrap: break-word;
white-space: pre;
}
<div class="container">
<p>thisisaverylongword anotherverylongword</p>
</div>
|
flex item overflows container due to long word even after using word-wrap
Tag : html , By : user86493
Date : March 29 2020, 07:55 AM
it helps some times Instead of setting a max-width for your flex item, use a min-width declaration. By default, if no min-width is set, the item's content min-width is assumed and the flex item's width will never be smaller. By setting a min-width of e.g. 40%, the item will shrink to at most 40% of the flex parent. .child2, .child3 {
min-width: 40%;
}
.parent{
width:100%;
display:flex;
flex-direction:row;
flex-wrap:nowrap;
padding:1em;
background-color:red;
box-sizing:border-box;
}
.child1{
background-color:mistyrose;
padding:1em;
}
.child2{
background-color:powderblue;
padding:.5em;
word-wrap: break-word;
overflow-wrap: break-word;
min-width: 40%;
}
.child3{
background-color:lightyellow;
padding:.5em;
word-wrap: break-word;
overflow-wrap: break-word;
min-width: 40%;
}
<div class="parent">
<div class="child1">
question
</div>
<div class="child2">
somethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomethingsomething
</div>
<div class="child3">
Works well with long URLs: <a href="#"> https://thisisadamnlongurlcontainingneitherhyphensoradditionalperiods.com</a>
</div>
</div>
|
Word-wrap: break-word does not work with a very long word combined with width: 100%
Tag : html , By : Marcos de Carvalho
Date : March 29 2020, 07:55 AM
|