PC Review


Reply
Thread Tools Rate Thread

Data Grid Columns Widths

 
 
Michael Hesse
Guest
Posts: n/a
 
      12th Dec 2003
This must have been covered a lot of times, but I still cannot seem to get
this work. I have a data table called "dt" and a data grid, "dg". The data
table is not part of a data set.

Here is my code. What am I doing wrong?
______________________________________
dg.SetDataBinding(dt, Nothing)

Dim dgts As DataGridTableStyle = New DataGridTableStyle

dgts.MappingName = "dt"

For i As Integer = 1 To 10

Dim CStyle As New DataGridTextBoxColumn

CStyle.Width = i * 100

dgts.GridColumnStyles.Add(CStyle)

Next

dg.TableStyles.Add(dgts)

dg.TableStyles("dt").GridColumnStyles(0).Width = 500

dg.TableStyles("dt").GridColumnStyles(1).Width = 2500

dg.Refresh()

_____________________________________________

Thanks for any help.


 
Reply With Quote
 
 
 
 
EricJ
Guest
Posts: n/a
 
      12th Dec 2003
i didn't adapt it to your case but this is working here (drgMain is the
datagrid)
hope it helps

dsForm = New DataSet("data")
dsForm = SqlHelper.ExecuteDataset(gstrCnn, CommandType.Text, strSql)
Dim ts As New DataGridTableStyle
ts.MappingName = "Table"

dgrMain.TableStyles.Clear()

dgrMain.SetDataBinding(dsForm, "Table")

dgrMain.TableStyles.Add(ts)
ts.GridColumnStyles(0).Width = 0
ts.GridColumnStyles(1).Width = 100
ts.GridColumnStyles(2).Width = 50
ts.GridColumnStyles(3).Width = 200

ts.AllowSorting = True
ts.AlternatingBackColor = Color.Lavender
ts.BackColor = Color.WhiteSmoke
ts.ForeColor = Color.MidnightBlue
ts.GridLineColor = Color.Gainsboro
ts.HeaderBackColor = Color.MidnightBlue
ts.HeaderForeColor = Color.WhiteSmoke
ts.LinkColor = Color.Navy
ts.SelectionBackColor = Color.Navy
ts.SelectionForeColor = Color.Lavender
ts.ColumnHeadersVisible = True

"Michael Hesse" <(E-Mail Removed)> wrote in message
news:kgcCb.70247$(E-Mail Removed)...
> This must have been covered a lot of times, but I still cannot seem to get
> this work. I have a data table called "dt" and a data grid, "dg". The

data
> table is not part of a data set.
>
> Here is my code. What am I doing wrong?
> ______________________________________
> dg.SetDataBinding(dt, Nothing)
>
> Dim dgts As DataGridTableStyle = New DataGridTableStyle
>
> dgts.MappingName = "dt"
>
> For i As Integer = 1 To 10
>
> Dim CStyle As New DataGridTextBoxColumn
>
> CStyle.Width = i * 100
>
> dgts.GridColumnStyles.Add(CStyle)
>
> Next
>
> dg.TableStyles.Add(dgts)
>
> dg.TableStyles("dt").GridColumnStyles(0).Width = 500
>
> dg.TableStyles("dt").GridColumnStyles(1).Width = 2500
>
> dg.Refresh()
>
> _____________________________________________
>
> Thanks for any help.
>
>



 
Reply With Quote
 
Michael Hesse
Guest
Posts: n/a
 
      12th Dec 2003
I am still having troubles. I wonder if it is becuse my data table isn't a
SQL table, but merely one I constucted myself. I guess I need to play with
this some more.

Thanks for the input.

Michael
"EricJ" <ericRé(E-Mail Removed)> wrote in message
news:3fd974f4$0$17573$(E-Mail Removed)...
> i didn't adapt it to your case but this is working here (drgMain is the
> datagrid)
> hope it helps
>
> dsForm = New DataSet("data")
> dsForm = SqlHelper.ExecuteDataset(gstrCnn, CommandType.Text,

strSql)
> Dim ts As New DataGridTableStyle
> ts.MappingName = "Table"
>
> dgrMain.TableStyles.Clear()
>
> dgrMain.SetDataBinding(dsForm, "Table")
>
> dgrMain.TableStyles.Add(ts)
> ts.GridColumnStyles(0).Width = 0
> ts.GridColumnStyles(1).Width = 100
> ts.GridColumnStyles(2).Width = 50
> ts.GridColumnStyles(3).Width = 200
>
> ts.AllowSorting = True
> ts.AlternatingBackColor = Color.Lavender
> ts.BackColor = Color.WhiteSmoke
> ts.ForeColor = Color.MidnightBlue
> ts.GridLineColor = Color.Gainsboro
> ts.HeaderBackColor = Color.MidnightBlue
> ts.HeaderForeColor = Color.WhiteSmoke
> ts.LinkColor = Color.Navy
> ts.SelectionBackColor = Color.Navy
> ts.SelectionForeColor = Color.Lavender
> ts.ColumnHeadersVisible = True
>
> "Michael Hesse" <(E-Mail Removed)> wrote in message
> news:kgcCb.70247$(E-Mail Removed)...
> > This must have been covered a lot of times, but I still cannot seem to

get
> > this work. I have a data table called "dt" and a data grid, "dg". The

> data
> > table is not part of a data set.
> >
> > Here is my code. What am I doing wrong?
> > ______________________________________
> > dg.SetDataBinding(dt, Nothing)
> >
> > Dim dgts As DataGridTableStyle = New DataGridTableStyle
> >
> > dgts.MappingName = "dt"
> >
> > For i As Integer = 1 To 10
> >
> > Dim CStyle As New DataGridTextBoxColumn
> >
> > CStyle.Width = i * 100
> >
> > dgts.GridColumnStyles.Add(CStyle)
> >
> > Next
> >
> > dg.TableStyles.Add(dgts)
> >
> > dg.TableStyles("dt").GridColumnStyles(0).Width = 500
> >
> > dg.TableStyles("dt").GridColumnStyles(1).Width = 2500
> >
> > dg.Refresh()
> >
> > _____________________________________________
> >
> > Thanks for any help.
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Grid displaying columns TWICE! =?Utf-8?B?cG11ZA==?= Microsoft Dot NET 3 25th Feb 2005 04:07 PM
Data Grid Column Widths sck10 Microsoft ASP .NET 3 15th Nov 2004 12:39 PM
custom data column headers, specific columns with web data grid =?Utf-8?B?YW5kcmV3Y3c=?= Microsoft C# .NET 0 9th Jul 2004 05:32 AM
Setting Column Widths in a Data Grid Control Byron O'Neal Microsoft VB .NET 2 18th Jun 2004 11:50 AM
Data Grid Columns Ann Marinas Microsoft C# .NET 1 20th Aug 2003 02:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:30 AM.