473,382 Members | 1,651 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,382 software developers and data experts.

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 2139
Jason,

You have to create a DataStyle for the datagrid.

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

private void ConfigureTestPointDatagrid()
{
DataGridTableStyle tsTP = new DataGridTableStyle();
tsTP.MappingName = "TestPoints Table";
tsTP.AlternatingBackColor = SystemColors.Control;

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

DataGridTextBoxColumn aliasIDCol = new DataGridTextBoxColumn();
aliasIDCol.MappingName = "aliasID";
aliasIDCol.HeaderText = "Alias ID";
aliasIDCol.Width = 80;
tsTP.GridColumnStyles.Add(aliasIDCol);

DataGridTextBoxColumn nameCol = new DataGridTextBoxColumn();
nameCol.MappingName = "parameterName";
nameCol.HeaderText = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumnStyles.Add(nameCol);

DataGridTextBoxColumn fiCol = new DataGridTextBoxColumn();
fiCol.MappingName = "Subsystem";
fiCol.HeaderText = "Subsystem";
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumnStyles.Add(fiCol);

DataGridColumnStyle idCol = new DataGridTextBoxColumn();
idCol.MappingName = "ID";
idCol.Width = 0;
tsTP.GridColumnStyles.Add(idCol);

testPointDatagrid.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?
"WhiteWizard" <Wh*********@discussions.microsoft.com> ¼¶¼g©ó¶l¥ó·s»D:45********************************* *@microsoft.com...
Jason,

You have to create a DataStyle for the datagrid.

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

private void ConfigureTestPointDatagrid()
{
DataGridTableStyle tsTP = new DataGridTableStyle();
tsTP.MappingName = "TestPoints Table";
tsTP.AlternatingBackColor = SystemColors.Control;

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

DataGridTextBoxColumn aliasIDCol = new DataGridTextBoxColumn();
aliasIDCol.MappingName = "aliasID";
aliasIDCol.HeaderText = "Alias ID";
aliasIDCol.Width = 80;
tsTP.GridColumnStyles.Add(aliasIDCol);

DataGridTextBoxColumn nameCol = new DataGridTextBoxColumn();
nameCol.MappingName = "parameterName";
nameCol.HeaderText = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumnStyles.Add(nameCol);

DataGridTextBoxColumn fiCol = new DataGridTextBoxColumn();
fiCol.MappingName = "Subsystem";
fiCol.HeaderText = "Subsystem";
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumnStyles.Add(fiCol);

DataGridColumnStyle idCol = new DataGridTextBoxColumn();
idCol.MappingName = "ID";
idCol.Width = 0;
tsTP.GridColumnStyles.Add(idCol);

testPointDatagrid.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.MappingName = mytb.TableName.ToString();

"Jason Huang" <Ja************@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:eG**************@TK2MSFTNGP05.phx.g bl...
Thansk White.
If my DataGrid's name is "dataGrid1", how do I implement your function for
my datagrid?
"WhiteWizard" <Wh*********@discussions.microsoft.com> ¼¶¼g©ó¶l¥ó·s»D:45********************************* *@microsoft.com...
Jason,

You have to create a DataStyle for the datagrid.

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

private void ConfigureTestPointDatagrid()
{
DataGridTableStyle tsTP = new DataGridTableStyle();
tsTP.MappingName = "TestPoints Table";
tsTP.AlternatingBackColor = SystemColors.Control;

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

DataGridTextBoxColumn aliasIDCol = new DataGridTextBoxColumn();
aliasIDCol.MappingName = "aliasID";
aliasIDCol.HeaderText = "Alias ID";
aliasIDCol.Width = 80;
tsTP.GridColumnStyles.Add(aliasIDCol);

DataGridTextBoxColumn nameCol = new DataGridTextBoxColumn();
nameCol.MappingName = "parameterName";
nameCol.HeaderText = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumnStyles.Add(nameCol);

DataGridTextBoxColumn fiCol = new DataGridTextBoxColumn();
fiCol.MappingName = "Subsystem";
fiCol.HeaderText = "Subsystem";
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumnStyles.Add(fiCol);

DataGridColumnStyle idCol = new DataGridTextBoxColumn();
idCol.MappingName = "ID";
idCol.Width = 0;
tsTP.GridColumnStyles.Add(idCol);

testPointDatagrid.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
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"...
0
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. ...
3
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...
0
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...
4
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,...
5
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...
2
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
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...
1
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
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.