Datagrids -> Custom Table and Column Styles???

D

Darryn Ross

Hi,

I am having a few problems with my datagrid, the data in my database isn't
coming through right. for example 100.00 in the table is coming through as
100 and 01/01/2004 in the table is coming through as 01/01/2004 10:45 AM???
how do i format my custom table and column styles to reflect the correct
data type stored in my tables... my code is as follows.



// Add a GridTableStyle and set the MappingName

// to the name of the DataTable.

DataGridTableStyle TSGLBatch = new DataGridTableStyle() ;

TSGLBatch.MappingName = "tblGLBatch" ;

try {

// Add a GridColumnStyle and set the MappingName

// to the name of a DataColumn in the DataTable.

// Set the HeaderText and Width properties.

DataGridColumnStyle TCTransNum = new DataGridTextBoxColumn() ;

TCTransNum.MappingName = "TransNum" ;

TCTransNum.HeaderText = "Trans Number" ;

TCTransNum.Width = 65 ;

TSGLBatch.GridColumnStyles.Add(TCTransNum) ;



DataGridColumnStyle TCCode = new DataGridTextBoxColumn() ;

TCCode.MappingName = "Code" ;

TCCode.HeaderText = "Chart Code" ;

TCCode.Width = 65 ;

TSGLBatch.GridColumnStyles.Add(TCCode) ;



DataGridColumnStyle TCReference = new DataGridTextBoxColumn() ;

TCReference.MappingName = "Reference" ;

TCReference.HeaderText = "Reference" ;

TCReference.Width = 65 ;

TSGLBatch.GridColumnStyles.Add(TCReference) ;



DataGridColumnStyle TCTDate = new DataGridTextBoxColumn() ;

TCTDate.MappingName = "TDate" ;

TCTDate.HeaderText = "Date" ;

TCTDate.Width = 75 ;

TSGLBatch.GridColumnStyles.Add(TCTDate) ;



DataGridColumnStyle TCAmount = new DataGridTextBoxColumn() ;

TCAmount.MappingName = "Amount" ;

TCAmount.HeaderText = "Amount" ;

TCAmount.Width = 65 ;

TSGLBatch.GridColumnStyles.Add(TCAmount) ;



TSGLBatch.AllowSorting = false ;

dgGLBatch.TableStyles.Add(TSGLBatch) ;

}

catch(Exception e) {

MessageBox.Show(e.Message, "AddCustomDataTableStyle", MessageBoxButtons.OK,
MessageBoxIcon.Error) ;

}








Regards

Darryn
 
G

Guest

hi,
i got your issue. So i think you know datagridstyle class. right. Now your
issue is individula column formatting.

See your code.

DataGridColumnStyle TCTransNum = new DataGridTextBoxColumn() ;

TCTransNum.MappingName = "TransNum" ;

TCTransNum.HeaderText = "Trans Number" ;

TCTransNum.Width = 65 ;

here you can set one more property that will deside in which format you can
show the content of that cell.

TCTransNum.Format="c" >>> this mean you want to show the content in
currency format which is complient to your culture info.

Like this you can show the content in different format.
If you have MSDN in your machine then please try to type the link that i
mention just below. There you will get lot of format froms. And how you need
to use that.


ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconcustomdatetimeformatstrings.htm


Please type this link in your VS.NET IDE help Url entry box.
 
D

Darryn Ross

i don't have the "Format" property listed against my DataGridColumnStyle ??
is there something i am not doing right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top