DataGrid
-
I have a DataGrid in my windows app. One of the fields is a date time type. It's showing up at a date in my DataGrid. I really need to see the time too. How can I change the format of this one field in the DataGrid?
-
I have a DataGrid in my windows app. One of the fields is a date time type. It's showing up at a date in my DataGrid. I really need to see the time too. How can I change the format of this one field in the DataGrid?
To change the format of a column, you need to set the Format property of the DataGridTextBoxColumn corresponding to the column. See the example code under DataGridTextBoxColumn should help. Burt Harris
-
To change the format of a column, you need to set the Format property of the DataGridTextBoxColumn corresponding to the column. See the example code under DataGridTextBoxColumn should help. Burt Harris
Thanks you for your reply. In my application I'm trying to display records in a table that let me know that some services I have written are working. At this point I'm updating the display on a button click. I tried to apply the code I found in the example you pointed me to. You can see the error message from my exception trap. Can you tell me where I when wrong? private void m_btnUpdate_Click(object sender, System.EventArgs e) { this.sqlDataAdapter1.Fill(this.imAliveDataSet1,0,0,"ImAlive"); // Gets the DataGridTextBoxColumn from the DataGrid control. DataGridTextBoxColumn myTextBoxColumn; myTextBoxColumn = null; // Assumes the Time column is a DataGridTextBoxColumn. try { myTextBoxColumn = (DataGridTextBoxColumn)dataGrid1. TableStyles["ImAlive"].GridColumnStyles["Time"]; } catch (Exception excpt) { string strMsg = string.Format("{0} Exception caught.", excpt); } // Gets the DataGridTextBox for the column. DataGridTextBox myGridTextBox; myGridTextBox = (DataGridTextBox) myTextBoxColumn.TextBox; strMsg "System.NullReferenceException: Object reference not set to an instance of an object. at FordMon.Form1.m_btnUpdate_Click(Object sender, EventArgs e) in c:\source\ford\fordmon\fordmon\form1.cs:line 227 Exception caught." string