title: C# cannot change DefaultCellStyle.WrapMode of a DataGridView
body: <p>I an using a DataGridView, which is bound to a DataTable. The DefaultCellStyle.WrapMode is set to false and everything is working just the way I want it. However, I want to use a custom CellPainting (code below), which does what is supposed to, but the WrapMode is no longer respected and longer strings are now wrapped when added to the "URL" column of DataGridView1.</p>
  
  <pre><code>  private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
     { 
         if (e.RowIndex &lt; 0) return;
  
         if (e.ColumnIndex == dataGridView1.Columns["URL"].Index)
         {
             if ((e.State &amp; DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
                 return;
             e.CellStyle.WrapMode = DataGridViewTriState.False;
             Rectangle rect = new Rectangle(e.CellBounds.X, e.CellBounds.Y,
                                            e.CellBounds.Width - 1, e.CellBounds.Height - 1);
  
             using (System.Drawing.Drawing2D.LinearGradientBrush lgb =
               new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Honeydew, 0f))
             {
                 e.Graphics.FillRectangle(lgb, rect);
             }
  
             if (e.Value == null) return;
  
             using (System.Drawing.Pen pen = new System.Drawing.Pen(dataGridView1.GridColor))
             {
                 e.Graphics.DrawRectangle(pen, e.CellBounds.X - 1, e.CellBounds.Y - 1,
                   e.CellBounds.Width, e.CellBounds.Height);
             }
  
             StringFormat sf = new StringFormat();
             sf.LineAlignment = StringAlignment.Center;
             sf.Alignment = StringAlignment.Near;
  
             using (System.Drawing.Brush valueBrush = new SolidBrush(e.CellStyle.ForeColor))
             {
                 e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, valueBrush, rect, sf);
  
             }
  
             e.Handled = true;
         }
  
       }
  </code></pre>
  
  <p>I have tried adding the following line:</p>
  
  <pre><code>dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.False;
  </code></pre>
  
  <p>it does not work, I have tried </p>
  
  <pre><code>e.CellStyle.WrapMode = DataGridViewTriState.False;
  </code></pre>
  
  <p>it does not work either.</p>
  
  <p>How do I use the custom CellPainting and set the <code>DefaultCellStyle.WrapMode</code> to false?</p>