PC Review


Reply
Thread Tools Rate Thread

datagrid cell width problem

 
 
Jason Huang
Guest
Posts: n/a
 
      21st Jun 2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2hpdGVXaXphcmQ=?=
Guest
Posts: n/a
 
      21st Jun 2006
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
>
>
>

 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      22nd Jun 2006
Thansk White.
If my DataGrid's name is "dataGrid1", how do I implement your function for
my datagrid?


"WhiteWizard" <(E-Mail Removed)> 撰寫於郵件新聞:4583DD1A-BDD1-431C-AA0D-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
Jason Huang
Guest
Posts: n/a
 
      23rd Jun 2006
tsTP.MappingName = mytb.TableName.ToString();

"Jason Huang" <(E-Mail Removed)> 撰寫於郵件新聞:(E-Mail Removed)...
> Thansk White.
> If my DataGrid's name is "dataGrid1", how do I implement your function for
> my datagrid?
>
>
> "WhiteWizard" <(E-Mail Removed)> 撰寫於郵件新聞:4583DD1A-BDD1-431C-AA0D-(E-Mail Removed)...
>> 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
>>>
>>>
>>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set grid cell width of DataGrid control? =?Utf-8?B?QW5kcmV3?= Microsoft ADO .NET 1 28th Oct 2004 02:23 AM
How to set the grid cell width of a DataGrid control? =?Utf-8?B?QW5kcmV3?= Microsoft Dot NET Framework Forms 0 27th Oct 2004 08:07 PM
adjust height & width of cell in datagrid Shri Microsoft C# .NET 0 9th Aug 2004 06:55 PM
Datagrid width problem CBN Media Microsoft ASP .NET 0 9th Mar 2004 12:57 AM
Datagrid cell height and width question JJ Microsoft VB .NET 0 26th Jan 2004 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:57 AM.