473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Data Grid Columns Widths

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.
Nov 20 '05 #1
2 1020
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" <mh****@sbcglobal.net> wrote in message
news:kg*******************@newssvr25.news.prodigy. com...
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.

Nov 20 '05 #2
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éMo**@ThiSomnipack.be> wrote in message
news:3f***********************@reader3.news.skynet .be...
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" <mh****@sbcglobal.net> wrote in message
news:kg*******************@newssvr25.news.prodigy. com...
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.


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sunny | last post by:
I am dealing with this problem for some time now, i want to find out if there is a way to change the Column widths of DataGrid based on the the maximum size of the cell (content) for that column, or...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
3
by: sck10 | last post by:
Hello, I am using a datagrid and am trying to control the column widths for each column. Is this possible? I have tried using the following: ControlStyle-BorderWidth="1000" with no apparent...
7
by: What-a-Tool | last post by:
Have an Access table loaded into a DataTable that was created at run time, and am displaying these contents in a data grid. Me.dgGames.DataSource = Me.DsGameInfo.Tables("Games") I would like to...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
0
by: Gian Paolo | last post by:
this is something really i can't find a reason. I have a form with a tabcontrol with tree pages, in the second page there is a Data GRid View. Plus i have a class. When i open the form i...
2
by: shotokan99 | last post by:
as of now im using this approach to take data: ===================================== require('conn.php'); $q='select * from '.$dbf_vid.' order by xrank'; $res=mysql_query($q) or die('error:...
9
by: trint | last post by:
How can I retrieve all of the data from a datagridview? Any help is appreciated. Thanks, Trint
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.