Shaitan00 Posted September 9, 2005 Posted September 9, 2005 Okay - note that I am open to all kinds of suggestions to solve this problem, there are probably millions of different/better ways to solve this then what I am about to propose so please feel free. Given a DataGrid [dgTask] and a DataSet [ds], I want to populate the Datagrid with the information from the dataset (at this point usually you just set dgTask.DataSource=ds.Tables[0];) BUT I need to make one minor customization to the results - this is where I am not sure of HOW to proceed. The DataSet.Tables[0] (and consequently resulting Datagrid) looks like this: [CLIENTS] [ASSIGNMENTS] [sTATUS] [ELAPSED TIME] Client1 Assignment1 PAUSED 150 Client1 Assignment2 RUNNING 500 Client2 Assignment1 PAUSED 456009 (...etc...) The [ELAPSED TIME] column is currently in SECONDS but I want to display it in a more user friendly format (HH:MM:SS) [something like TimeSpan: tsElapsedTime = new TimeSpan(0, 0, 0, (int)dElapsedTimeSeconds, 0);]. So - the question is how to format the data in the column? Do I a) modify the dataset and then set it as a datasource for the datagrid OR b) do I populate the datagrid cells manually therefore giving me control on formatting the data of that specific column? I would assume (A) would be the correct answer, I just have absolutly no clue how to modify the contents of all the cells in the Column from an integer value (representing SECONDS) to a correctly formatted timespan value? Can I loop through? something like (pseudo-code) "foreach row in Dataset, if row.colums[5] then format data somehow"?? Any help/hints would be greatly appreciated...Thanks, Quote
penfold69 Posted September 12, 2005 Posted September 12, 2005 Attach a DataGridTableStyle to your DataGrid, and then set the FORMAT of the relevant column. As a (very rough, untested and top-of-the-head) idea: YourDataGrid.Datasource = YourDataSet Dim ts as New DataGridTableStyle Dim col1 as New DataGridTextBoxColumn col1.MappingName="ELAPSED TIME" col1.HeaderText = "Elapsed Time" col1.Format = "hh:mm:ss" col1.Width = 100 ts.GridColumnStyles.Add(col1) ' (continue adding columns for each column you wish to display) YourDataGrid.TableStyles.Clear() YourDataGrid.TableStyles.Add(ts) B. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.