473,785 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[c# win form] datagrid column width help?

77 New Member
Hi, i have a DataGrid (dgFailed) and it gets populated with two columns (which comes from arrays and sql db values). the table that populates the datagrid(dataso urce) is called tblfailed.
Expand|Select|Wrap|Line Numbers
  1. tblfailed
  2. Student | Reason
  3. Fred      | No Contact Info
  4. james   | Cancel Button Pressed
  5.  
Now the reason is generally always going to be longer then the name. so i need to be able to set the width of the Reason column so fit the rest of the table, 1) so it looks neat and doesnt leave grey around the edges 2) so if it get longer then they can see the rest of the reason.

the width of the datagrid is 400.

Can Anyone help?

many thanks,
Piercy
Sep 12 '07 #1
3 1516
dip_developer
648 Recognized Expert Contributor
Hi, i have a DataGrid (dgFailed) and it gets populated with two columns (which comes from arrays and sql db values). the table that populates the datagrid(dataso urce) is called tblfailed.
Expand|Select|Wrap|Line Numbers
  1. tblfailed
  2. Student | Reason
  3. Fred | No Contact Info
  4. james | Cancel Button Pressed
  5.  
Now the reason is generally always going to be longer then the name. so i need to be able to set the width of the Reason column so fit the rest of the table, 1) so it looks neat and doesnt leave grey around the edges 2) so if it get longer then they can see the rest of the reason.

the width of the datagrid is 400.

Can Anyone help?

many thanks,
Piercy

see this link......
hope this will help u
Sep 12 '07 #2
piercy
77 New Member
yes, i tried this but i got a object reference not set to an instance of an object error.

Expand|Select|Wrap|Line Numbers
  1.             DataGridTableStyle ts = new DataGridTableStyle();
  2.             ts.MappingName = "tblfailed";
  3.             this.dgFailed.TableStyles.Clear();
  4.             this.dgFailed.TableStyles.Add(ts);
  5.  
  6.             dgFailed.TableStyles["tblfailed"].GridColumnStyles["Reason"].Width = 350;
  7.  
Thats what i tried. i also tried it replacing "Reason" with 1 (hopeful attempt at column index) but it said index out of range...


Thanks,
Piercy
Sep 12 '07 #3
dip_developer
648 Recognized Expert Contributor
yes, i tried this but i got a object reference not set to an instance of an object error.

Expand|Select|Wrap|Line Numbers
  1.             DataGridTableStyle ts = new DataGridTableStyle();
  2.             ts.MappingName = "tblfailed";
  3.             this.dgFailed.TableStyles.Clear();
  4.             this.dgFailed.TableStyles.Add(ts);
  5.  
  6.             dgFailed.TableStyles["tblfailed"].GridColumnStyles["Reason"].Width = 350;
  7.  
Thats what i tried. i also tried it replacing "Reason" with 1 (hopeful attempt at column index) but it said index out of range...


Thanks,
Piercy
add a tablestyle,add a textbox or label control as you want and then set the width of that textbox or label as per youe requirement.... ....set the datasource property of the textbox(or label) with which you are binding the textbox(or label) in the mappingname property....... ...
the code will look like

Expand|Select|Wrap|Line Numbers
  1.  
  2.         DataGridTableStyle dgtsMystyle = New DataGridTableStyle;
  3.         dgtsMystyle .MappingName = "tblfailed";
  4.         DataGridTextBoxColumn  myBox = New DataGridTextBoxColumn;
  5.         myBox .MappingName = "databaseField";
  6.         myBox .HeaderText = "myHeader";
  7.         myBox .Width = 350;
  8.         myBox .TextBox.BackColor = Color.LightBlue;
  9.         dgtsMystyle .GridColumnStyles.Add(myBox );
  10.  
Sep 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1716
by: Hajash | last post by:
hi all, how do i set the width of a column in a datagrid.Please help.Thanks in advance. regards, hajash
1
2483
by: Drew | last post by:
Hey, thanks in advance for helping me out with my problem: I have a datagrid which is embedded in another datagrid. The datagrid is filled directly by a dataset generated from a sql query. So far everything is fine. Now i try to format the embedded datagrid - e.g. setting font size and the column size/width of each column. Everything is working fine, except the width of the columns.
0
2624
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the header row - and they conflict. The sortable column apparently uses the generic style for <a> elements and the rest of the header uses "headerRow". Can anyone tell me how to get consistent styles for each column in my datagrid header?
4
1829
by: Steve | last post by:
I am fairly new to VB.NET, and I am rewriting an application I wrote a while back, also in VB.NET. I aplied some new things I learned. Anyway, here is my problem....... I have a custom DataGrid with a buttonRow that does a delete function for me. Microsoft support helped me back then to get this done. Here is part of the code that creates the dataGrid: Dim ButtonColStyle As DataGridButtonColumn
5
5914
by: Genojoe | last post by:
I am using code from Help with two exceptions. (1) I increased the number of sample rows from 3 to 20, and (2) I anchored the datagrid to bottom of form so that I can change the size of the grid by changing the size of the form The code is at the following location in the January, 2004 help ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpref/html/frlrfSystemWindowsFormsDataGridClassTopic.ht You can also find it by doing a search for...
17
7438
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5 columns in it but i need to add a sixth column which will be my checkbox column - any help or pointers with this would be great
0
1387
by: Ben | last post by:
module main ... application.run(new splashform) .. end module after a few screen, I try to load a new codes I got from MSDN on datagrid that works on its own. I took out submain and ran datagridForm from my mainForm:
2
10406
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat actually happens is... when the Text size is too big... the column
2
3443
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3 datagrida. I would like to set it so that if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to green if value of column 3 in datagrid 3is < 80 set to red,...
2
6596
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the itemsource shows the info is there. Know if I click on the child cell and then click back on the...
0
9480
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
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
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
8971
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...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
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
5380
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.