2013-12-16 35 views
0

我有sqlite連接的datagridview。 下面是代碼:數據源視圖的格式

dataGridView.AutoGenerateColumns = false; 
    SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source=data;"); 
    connection.Open(); 
    string sql = "SELECT * FROM users"; 
    DataSet DS = new DataSet(); 
    SQLiteDataAdapter DA = new SQLiteDataAdapter(sql, connection); 
    DA.Fill(sqlDS); 
    dataGridView.DataSource = DS.Tables[0].DefaultView; 
    dataGridView.Update(); 

我的datagridview與像SQLite中的頭表的名稱列propertyName的。所以數據會自動插入datagridview的同名列中。

我有問題:我如何格式化數據列? 例如:我有一個標題名稱爲「Date」的列。 sqlite表中的同名。只有日期,但我想看到:「這個」+日期+「日!」

回答

1

嘗試CellFormatting事件:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    if ((e.ColumnIndex == 0) 
     e.Value = "This" + e.Value.ToString() + " day!"; 
}