Habe bis auf ein kleines Problem hinbekommen und hoffe jemand kann mir helfen, komme einfach nicht weiter.
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Rows.Add(false, "Kunde: ");
dataGridView1.Rows.Add(false, "Service Auftrag: ");
dataGridView1.Rows.Add(false, "Fabrikat: "+ "Ich schreibe hier mal ein paar Testworte um zu sehen wie es bei langen Sätzen so funktioniern wird.");
dataGridView1.Rows.Add(false, "Typ: ");
dataGridView1.Rows.Add(false, "S/N: ");
dataGridView1.Rows.Add(false, "Zustand: ");
dataGridView1.Rows.Add(false, "Zubehör: ");
dataGridView1.Rows.Add(false, "Fehler: ");
dataGridView1.Rows.Add(false, "Kaufdatum: ");
dataGridView1.Rows.Add(false, "Artikel-Nr.: ");
dataGridView1.Rows.Add(false, "Policen-Nr.: ");
dataGridView1.Rows.Add(false, "RetourenNr.: ");
dataGridView1.Rows.Add(false, "RMA-Nr.: ");
dataGridView1.Rows.Add(false, "Beleg: " + "Ich schreibe hier mal ein paar Testworte um zu sehen wie es bei langen Sätzen so funktioniern wird.");
}
private void dataGridView1_CellPainting(object sender,System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
if(e.Value!=null)
if (this.dataGridView1.Columns["Column2"].Index ==
e.ColumnIndex && e.RowIndex >= 0)
{
int start = 0;
int end = e.Value.ToString().IndexOf(":");
string teil = e.Value.ToString().Substring(start, end+1);
string teilende = e.Value.ToString().Substring(end +2);
Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
e.CellBounds.Y + 1, e.CellBounds.Width - 4,
e.CellBounds.Height -4);
using (
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// Erase the cell.
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
// Draw the grid lines (only the right and bottom lines;
// DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom);
// Draw the inset highlight box.
e.Graphics.DrawRectangle(Pens.Blue, newRect);
// Draw the text content of the cell, ignoring alignment.
//if (e.Value != null)
//{
e.Graphics.DrawString(teil, new Font(e.CellStyle.Font, FontStyle.Bold),
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y + 2, StringFormat.GenericDefault);
SizeF pos = new SizeF(e.Graphics.MeasureString(teil, new Font(e.CellStyle.Font, FontStyle.Bold)));
RectangleF newRectnew = new RectangleF(e.CellBounds.X+pos.Width,e.CellBounds.Y+2,newRect.Width-pos.Width,newRect.Height);
e.Graphics.DrawString(teilende, new Font(e.CellStyle.Font, FontStyle.Regular),
Brushes.Black, newRectnew, StringFormat.GenericDefault);
//}
e.Handled = true;
}
}
}
}
die letzten Worte werden immer abgeschnitten und nicht dargestellt, finde allerdings keinen Fehler bzw. eine Lösung.