473,756 Members | 8,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting datagrid column widths in code?

Hello,

I have a one datagrid that will be based on different datatables. One
datatable may have 7 columns, another 15... With the tables that have more
columns, I have been manually dragging column widths to narrow them. I want
to record these widths so I can reapply them when I bind the datagrid to the
table with 15 columns. I have searched around for articles on this and saw
some that talked about datagrid.TableS tyle.GridColumn Style something, but on
intellisense of my datagrid I got TableStyles and no GridColumnStyle s. I
would be very grateful if someone could set me straight on how I can retrieve
and set column widths for a datagrid from code. Do I need to use a dataview
maybe to do this?

Thanks,
Rich
Jan 27 '06 #1
4 4193
Rich wrote:
Hello,

I have a one datagrid that will be based on different datatables. One
datatable may have 7 columns, another 15... With the tables that have more
columns, I have been manually dragging column widths to narrow them. I want
to record these widths so I can reapply them when I bind the datagrid to the
table with 15 columns. I have searched around for articles on this and saw
some that talked about datagrid.TableS tyle.GridColumn Style something, but on
intellisense of my datagrid I got TableStyles and no GridColumnStyle s. I
would be very grateful if someone could set me straight on how I can retrieve
and set column widths for a datagrid from code. Do I need to use a dataview
maybe to do this?

Thanks,
Rich


I can tell you how to do the GridColumnStyle (it's
datagrid.TableS tyle(0).GridCol umnStyle) but there is a better way.

If you add one TableStyle for each of the datatables you are using the
grid will change automatically depending on which datatable is bound to
it. The key that seems to get missed often on doing this is to make
sure the TableStyle.Mapp ingName matches the name of the datatable.

Hope this helps.
Chris
Jan 27 '06 #2
I am having a problem setting a table style for my datatable. How do I do
that?

Dim dt As DataTable
dt = Dataset1.Tables ("tbl1")
dt.???????
datagrid1.DataS ource = dt


I can tell you how to do the GridColumnStyle (it's
datagrid.TableS tyle(0).GridCol umnStyle) but there is a better way.

If you add one TableStyle for each of the datatables you are using the
grid will change automatically depending on which datatable is bound to
it. The key that seems to get missed often on doing this is to make
sure the TableStyle.Mapp ingName matches the name of the datatable.

Hope this helps.
Chris

Jan 27 '06 #3
Rich wrote:
I am having a problem setting a table style for my datatable. How do I do
that?

Dim dt As DataTable
dt = Dataset1.Tables ("tbl1")
dt.???????
datagrid1.DataS ource = dt
I can tell you how to do the GridColumnStyle (it's
datagrid.Tabl eStyle(0).GridC olumnStyle) but there is a better way.

If you add one TableStyle for each of the datatables you are using the
grid will change automatically depending on which datatable is bound to
it. The key that seems to get missed often on doing this is to make
sure the TableStyle.Mapp ingName matches the name of the datatable.

Hope this helps.
Chris

You set the tablestyle of the datagrid.
(doing this from memory, but you'll get the idea)

'Do this for each table
Dim DT as new DataGridTableSt yle
DT.MappingName = "tbl1" '<--Important!

'Add one for each column you want displayed
Dim Column as new DataGridTextBox Column
Column.Width = 100
Column.DisplayN ame = ... 'This might be wrong property
Column.MappingN ame = ... 'This might be wrong property
DT.DataGridColu mnStyle.Add(Col umn)
Column = new DataGridTextBox Column
Column.Width = 150
Column.DisplayN ame = ... 'This might be wrong property
Column.MappingN ame = ... 'This might be wrong property
DT.DataGridColu mnStyle.Add(Col umn)

DataGrid1.Table Styles.Add(DT)

Dim dt As DataTable
datagrid1.DataS ource = Dataset1.Tables ("tbl1")

Hope this helps
Chris
Jan 27 '06 #4
Thanks. This should do the trick. I might have to tweak it a little bit.
But yes I get the idea now.

Rich

"Chris" wrote:
Rich wrote:
I am having a problem setting a table style for my datatable. How do I do
that?

Dim dt As DataTable
dt = Dataset1.Tables ("tbl1")
dt.???????
datagrid1.DataS ource = dt
I can tell you how to do the GridColumnStyle (it's
datagrid.Tabl eStyle(0).GridC olumnStyle) but there is a better way.

If you add one TableStyle for each of the datatables you are using the
grid will change automatically depending on which datatable is bound to
it. The key that seems to get missed often on doing this is to make
sure the TableStyle.Mapp ingName matches the name of the datatable.

Hope this helps.
Chris

You set the tablestyle of the datagrid.
(doing this from memory, but you'll get the idea)

'Do this for each table
Dim DT as new DataGridTableSt yle
DT.MappingName = "tbl1" '<--Important!

'Add one for each column you want displayed
Dim Column as new DataGridTextBox Column
Column.Width = 100
Column.DisplayN ame = ... 'This might be wrong property
Column.MappingN ame = ... 'This might be wrong property
DT.DataGridColu mnStyle.Add(Col umn)
Column = new DataGridTextBox Column
Column.Width = 150
Column.DisplayN ame = ... 'This might be wrong property
Column.MappingN ame = ... 'This might be wrong property
DT.DataGridColu mnStyle.Add(Col umn)

DataGrid1.Table Styles.Add(DT)

Dim dt As DataTable
datagrid1.DataS ource = Dataset1.Tables ("tbl1")

Hope this helps
Chris

Jan 27 '06 #5

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

Similar topics

3
5375
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable( "SELECT 'Task' AS 'Type', title AS 'Title', IFNULL(u.name, 'Nobody') AS 'Assigned To' FROM tasks t LEFT JOIN users u ON t.assigned_to=u.user_id LIMIT 0, 30" ); grid.ReadOnly = true;
9
3945
by: web1110 | last post by:
Hi y'all, I have resized the columns in a DataGrid and I want to set the width of the DataGrid to fit the columns. Just summing the column widths is too short due to the grid and gray row selection column on the left. I have the widths of the columns. What other values do I need to include in the DataGrid width? Thanx,
1
1234
by: coleenholley | last post by:
I'm getting frustrated with trying to format a datagrid that is entirely populated dynamically using a class module written in VB .Net (No C# used!) We connect to a DB2 database using an RPC that is written in COBOL. The connection to the datagrid works in the code-behind in the class module, when I check the 'Create columns automatically at run time' box. If I don't select that, I don't get any data, even if I go in and add all my columns in...
2
6412
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
6
7108
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000 datagrid1.columns(1).width = 1000 Except that there is no such things as a columns collection in a datagrid.
4
1906
by: Jeff | last post by:
I am stuck on trying to generate two columns headers for a datagrid on form load. I can use a datatable as the datasource and get the results I want, but I want to set different column widths and don't see a way to do this through the datagrid properties. I am not using a database connection, I just want to set column headers on the datagrid. I am somewhat new to vb.net. Here is the code I am using. This code works when the...
4
15427
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are all set to the default. But after paging to another page, the widths are set as they should be. Going back to page one, the widths are still correct. Not a clue what's going on here!
2
11722
by: Jacksm | last post by:
How can I align an asp:table columns with gridview columns (the widths)? I have tried setting table.column(0).width = gridview.column(0).width at page_load but it doesn't work. Thanks in advance
5
1953
by: vpravin | last post by:
Hi guys...i am a super noob with html and aspx.. i didnt start this project but i am modifying it... q: how do i change the width of a column: Thats the table which is within a text box <asp:Table id="regulatoryDetails" runat="server" Font-Size="X-Small" Width="400px" Height="8px"
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.