//把目前選到的值存起來
String CurrentCellValue;
CurrentCellValue = myDataGridView.CurrentCell.Value.ToString();


//驗證每一個Cell格子的輸入

用事件CellValidating

if (DataGridView1.Columns[e.ColumnIndex].Name == "welkin")
{
  if (e.FormattedValue.ToString() == "")
 {
    DataGridView1.Rows[e.RowIndex].ErrorText = "不要空白阿";
    e.Cancel = true;
 }
else
 {
   DataGridView1.Rows[e.RowIndex].ErrorText = "";
 }
}

//對每一個格子和內容進行樣式的設定
用事件CellPainting
e.Graphics.FillRectangle(Brushes.Blue, e.CellBounds);
if (e.Value != null)
{
   e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
      Brushes.Black, e.CellBounds.X, e.CellBounds.Y);
}

//最後加這行,不然會好像被預設的蓋過
e.Handled = true;

 

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()