473,788 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid cell width problem

Hi,

In my C# Windows form project.
I am wondering can we manually define the width of a cell in a DataGrid?
Thanks for help.
Jason
Jun 21 '06 #1
3 2158
Jason,

You have to create a DataStyle for the datagrid.

Here is an example of one I use in my WinApp.

private void ConfigureTestPo intDatagrid()
{
DataGridTableSt yle tsTP = new DataGridTableSt yle();
tsTP.MappingNam e = "TestPoints Table";
tsTP.Alternatin gBackColor = SystemColors.Co ntrol;

/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */

DataGridTextBox Column aliasIDCol = new DataGridTextBox Column();
aliasIDCol.Mapp ingName = "aliasID";
aliasIDCol.Head erText = "Alias ID";
aliasIDCol.Widt h = 80;
tsTP.GridColumn Styles.Add(alia sIDCol);

DataGridTextBox Column nameCol = new DataGridTextBox Column();
nameCol.Mapping Name = "parameterName" ;
nameCol.HeaderT ext = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumn Styles.Add(name Col);

DataGridTextBox Column fiCol = new DataGridTextBox Column();
fiCol.MappingNa me = "Subsystem" ;
fiCol.HeaderTex t = "Subsystem" ;
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumn Styles.Add(fiCo l);

DataGridColumnS tyle idCol = new DataGridTextBox Column();
idCol.MappingNa me = "ID";
idCol.Width = 0;
tsTP.GridColumn Styles.Add(idCo l);

testPointDatagr id.TableStyles. Add(tsTP);
}

HTH
"Jason Huang" wrote:
Hi,

In my C# Windows form project.
I am wondering can we manually define the width of a cell in a DataGrid?
Thanks for help.
Jason

Jun 21 '06 #2
Thansk White.
If my DataGrid's name is "dataGrid1" , how do I implement your function for
my datagrid?
"WhiteWizar d" <Wh*********@di scussions.micro soft.com> ¼¶¼g©ó¶l¥ó·s»D: 45************* *************** ******@microsof t.com...
Jason,

You have to create a DataStyle for the datagrid.

Here is an example of one I use in my WinApp.

private void ConfigureTestPo intDatagrid()
{
DataGridTableSt yle tsTP = new DataGridTableSt yle();
tsTP.MappingNam e = "TestPoints Table";
tsTP.Alternatin gBackColor = SystemColors.Co ntrol;

/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */

DataGridTextBox Column aliasIDCol = new DataGridTextBox Column();
aliasIDCol.Mapp ingName = "aliasID";
aliasIDCol.Head erText = "Alias ID";
aliasIDCol.Widt h = 80;
tsTP.GridColumn Styles.Add(alia sIDCol);

DataGridTextBox Column nameCol = new DataGridTextBox Column();
nameCol.Mapping Name = "parameterName" ;
nameCol.HeaderT ext = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumn Styles.Add(name Col);

DataGridTextBox Column fiCol = new DataGridTextBox Column();
fiCol.MappingNa me = "Subsystem" ;
fiCol.HeaderTex t = "Subsystem" ;
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumn Styles.Add(fiCo l);

DataGridColumnS tyle idCol = new DataGridTextBox Column();
idCol.MappingNa me = "ID";
idCol.Width = 0;
tsTP.GridColumn Styles.Add(idCo l);

testPointDatagr id.TableStyles. Add(tsTP);
}

HTH
"Jason Huang" wrote:
Hi,

In my C# Windows form project.
I am wondering can we manually define the width of a cell in a DataGrid?
Thanks for help.
Jason

Jun 22 '06 #3
tsTP.MappingNam e = mytb.TableName. ToString();

"Jason Huang" <Ja************ @hotmail.com> ¼¶¼g©ó¶l¥ó·s»D: eG************* *@TK2MSFTNGP05. phx.gbl...
Thansk White.
If my DataGrid's name is "dataGrid1" , how do I implement your function for
my datagrid?
"WhiteWizar d" <Wh*********@di scussions.micro soft.com> ¼¶¼g©ó¶l¥ó·s»D: 45************* *************** ******@microsof t.com...
Jason,

You have to create a DataStyle for the datagrid.

Here is an example of one I use in my WinApp.

private void ConfigureTestPo intDatagrid()
{
DataGridTableSt yle tsTP = new DataGridTableSt yle();
tsTP.MappingNam e = "TestPoints Table";
tsTP.Alternatin gBackColor = SystemColors.Co ntrol;

/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */

DataGridTextBox Column aliasIDCol = new DataGridTextBox Column();
aliasIDCol.Mapp ingName = "aliasID";
aliasIDCol.Head erText = "Alias ID";
aliasIDCol.Widt h = 80;
tsTP.GridColumn Styles.Add(alia sIDCol);

DataGridTextBox Column nameCol = new DataGridTextBox Column();
nameCol.Mapping Name = "parameterName" ;
nameCol.HeaderT ext = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumn Styles.Add(name Col);

DataGridTextBox Column fiCol = new DataGridTextBox Column();
fiCol.MappingNa me = "Subsystem" ;
fiCol.HeaderTex t = "Subsystem" ;
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumn Styles.Add(fiCo l);

DataGridColumnS tyle idCol = new DataGridTextBox Column();
idCol.MappingNa me = "ID";
idCol.Width = 0;
tsTP.GridColumn Styles.Add(idCo l);

testPointDatagr id.TableStyles. Add(tsTP);
}

HTH
"Jason Huang" wrote:
Hi,

In my C# Windows form project.
I am wondering can we manually define the width of a cell in a DataGrid?
Thanks for help.
Jason


Jun 23 '06 #4

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

Similar topics

8
2340
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3" ItemStyle-HorizontalAlign="center" ItemStyle-VerticalAlign="top"> <ItemTemplate><%# CType(Container.DataItem("DateStatut"),DateTime).ToString("yyyy-MM-dd") %></ItemTemplate> <EditItemTemplate> <asp:TextBox width="80" CssClass="edit_item" id="txtDateStatut"
0
1571
by: Job Lot | last post by:
I have an Expense Data Entry form which contains a DataGrid showing various expense categories. There are three columns Description, Cash Exp, Credit Exp, where Description column is readonly. Users have to press a checkbox to specify whether they want to use DataGrid to provide break-up or provide total value in textbox. Now when checkbox is unchecked I am setting the Enabled property of DataGrid to False and vice versa. The problem is...
3
3031
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
0
3551
by: Mauro | last post by:
Hi, I need a big help to resolve this problem. I need to put a usercontrol in a datagrid: this control check if the code inserted is present in a archive and if not return a error message. (In the example I have changed this check with a easy "if string is empty" ) Everything would be easy if the datagrid had a predictable behaviour. I explain my problem.
4
1229
by: Kristoffer Arfvidson | last post by:
Im trying to get access to a table in codebehind, because the information in this table is different depending on what it says in the database... So, either I have to access it from codebehind, or Ill have to make bit of code on the aspx page... However, I would prefere code in the aspx page at the moment, but it seemed easier to access thecode from codebehind... However... When I run the following code, (when I look at the code it...
5
3510
by: Brian Henry | last post by:
I have a messaging application that has a data grid with information like an email list would have (from, subject, time sent, size) but the subject could be very long in theory, and then it would word wrap.. the subject is a variable width column (resizes to fit space) while the others are fixed size... the problem is that i dont want the text to ever word wrap.. but truncate the visible subject to match the current cell width... (kinda...
2
6414
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
8
1552
by: Scott Meddows | last post by:
I have a datagrid control that I've inherited from the base datagrid control (Source below). I am applying a datatable style onto the datatable that I assign as my datasource. All of my column but one are set as readonly=true. The writeable column does not update when I'm editing it. Is there something different that I need to be doing to update this data? Also, how do I get the "new row" to not appear at the bottom of the datagrid?...
1
2031
by: Tarik Monem | last post by:
Hi everyone and I hope that you can help. I am trying to send a value of a cell within a Datagrid to my php file which has a simple sql query: here's the php: <? $server = "localhost";
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
9498
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,...
1
10110
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
9967
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
8993
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
7517
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
6750
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
5398
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...
1
4069
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.