DataGrid Column widths not changing - help!!!

A

Andre Ranieri

I forgot to ask, but are there any properties and methods
that would allow me to customize the output formatting of
the bound columns? For example, I'd like the date
completed to show in short date format, the balance to
show as a decimal/currency.

Thanks,

Andre






I'm trying to programmatically create columns for a
datagrid and set
their width. The "Services" field especially has a fairly
long text
value, I'd like to make it wider than the default.

I've scoured the MSDN library and the newsgroups, and have
tried
setting the Itemstyle.Width of the bound column as well as
dgRecentServices.Columns
[1].ItemStyle.Width = Unit.Pixel(400);.

Would someone please point me in the right direction? I'm
not sure
what I'm doing wrong.

Thanks,

Andre




private void dgFillRecent()
{

BoundColumn bc = new BoundColumn();
bc.HeaderText = "Invoice";
bc.DataField = "ServiceID";
bc.ItemStyle.Width = Unit.Pixel
(500);
dgRecentServices.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Service";
bc.DataField = "Service";
dgRecentServices.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Status";
bc.DataField = "Status";
dgRecentServices.Columns.Add(bc);

bc = new BoundColumn();
bc.DataField = "DateCompleted";
bc.HeaderText = "Date ";
dgRecentServices.Columns.Add(bc);

bc = new BoundColumn();
bc.DataField = "AmountCompleted";
bc.HeaderText = "Amount";
dgRecentServices.Columns.Add(bc);

bc = new BoundColumn();
bc.DataField = "Balance";
bc.HeaderText = "Balance";
dgRecentServices.Columns.Add(bc);


dgRecentServices.Columns
[1].ItemStyle.Width = Unit.Pixel(400);

}





private void RecentServices(String sAccountKey,
SqlConnection cn)
{
DateTime datNow = DateTime.Now;

dgFillRecent();

string sSQL = "SELECT TOP 7 Service,
Status, PreNotifyType, " +
"DateScheduled, ServiceID,
DateCompleted, AmountCompleted, Balance
" +
"FROM dbo.tblMainServices " +
"WHERE (AccountKey = " +
sAccountKey + ") AND (DateCompleted < '" +
datNow + "') " +
"ORDER BY DateCompleted DESC;";
SqlDataAdapter da = new
SqlDataAdapter();
da.SelectCommand = new SqlCommand
(sSQL, cn);
DataSet ds = new DataSet();

da.Fill(ds, "LastServices");
DataTable LastServices;
LastServices = ds.Tables
["LastServices]"];
string sService, sStatus,
sPreNotifyType, sServiceID;
DateTime datDateScheduled,
datDateCompleted;
decimal decSaleAmount, decBalance;


dgRecentServices.DataSource=ds.Tables
["LastServices"];

DataView source = new DataView
(ds.Tables[0]);
dgRecentServices.DataSource =
source ;
dgRecentServices.DataBind();
..
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top