我正在使用SQL Server 2005和Visual Studio 2008,C#。如何操作綁定到數據源的DataGridView上的格式?
在數據源(SQL Server數據表)我使用的DateTime格式爲mm/dd/yyyy的,然而,在一個形式概述(DataGridView中)的用戶希望看到一個完全其他格式, (yyww,d)這是在字符串格式的年份,星期數和星期數。 我已經創建了一個值之間的轉換算法(日期到星期幾),但我可以用yyww,d(字符串)而不是mm/dd/yyyy(DateTime)填充受影響的單元格嗎?
這是從來就被檢測出來,但沒有成功 (和註釋,it's在最後一行的問題變得很明顯,作爲單元格的值不需額外接受運行時串 - 它仍然想成爲一個日期時間 ...)
private void DataGridViewQueryFindRequests_CellFormatting(
object sender, DataGridViewCellFormattingEventArgs e)
{
string weekAndDay = "";
DataGridViewCell cell =
DataGridViewQueryFindRequests.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell.ColumnIndex == 13 && cell.Value == null)
mEmptyRow = true;
if ((cell.ColumnIndex == 14 || cell.ColumnIndex == 15) && !mEmptyRow)
{
weekAndDay = ClassWeeksAndDates.dateToWeekNumber(Convert.ToDateTime(cell.Value));
cell.ValueType = typeof(string);
cell.Value = weekAndDay;
}
}
嗨,就是這個問題,從這個有什麼不同? http://stackoverflow.com/questions/3051192/is-it-possible-to-manipulate-the-format-on-a-datagridview-that-is-bound-to-a-data你還在尋找答案這裏? – 2010-06-16 21:55:21
是的,我是,你不客氣。 – 2010-06-16 22:09:56