DataGrid显示的时间为什么没有“时、分、秒”?——WinForm中对DataGrid应用样式

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

SqlConnection conn = new SqlConnection( "server=(local);Database=prjmaster;uid=sa;pwd=123456" );

SqlDataAdapter da = new SqlDataAdapter( "SELECT TOP 10 * FROM Bug", conn );

DataSet ds = new DataSet();

try

{

da.Fill( ds, "BugTable" );

}

catch( Exception ex )

{

MessageBox.Show( ex.Message );

}

dataGrid1.DataSource = ds.Tables["BugTable"];

CurrencyManager myCurrencyManger = //获取对象列表管理器

(CurrencyManager)this.BindingContext[ds];

DataGridTableStyle myTableStyle = new DataGridTableStyle(); //创建表样式

myTableStyle.MappingName = "BugTable";

PropertyDescriptor myDateDescriptor = //获取包含日期的列的PropertyDescriptor

myCurrencyManger.GetItemProperties()["bugopendate"];

// 'G' is for MM/dd/yyyy HH:mm:ss date format.

DataGridColumnStyle myDateStyle = //创建列样式

new DataGridTextBoxColumn(myDateDescriptor,"G");

myDateStyle.MappingName = "bugopendate"; //数据库中的列名

myDateStyle.HeaderText = "Bug Open Date"; //要显示在DataGird表头上的文字

myDateStyle.Width = 150; //宽度

/*如果你想显示多个列,就要生成多个DataGridColumnStyle对象*/

DataGridColumnStyle column2 = new DataGridTextBoxColumn();

column2.MappingName = "bugassignto";

column2.HeaderText = "Bug接收者";

myTableStyle.GridColumnStyles.Add(myDateStyle); //加入列样式

myTableStyle.GridColumnStyles.Add(column2);

dataGrid1.TableStyles.Add(myTableStyle); //将表样式加入DataGrid

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航