.NETGURU
db grid
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Paps (VIP)
Hi all,

I have populated my grid from a dataSet.

1) I want to enter certain values and in Caps in my second col. Like I want
to enter only 'PAT' or 'SAT'. is this possible.

2) When my Grid populatyes the fourth col is not fully visible. I will have
to increase the width each time when it displays. Is it possible to set the
width of the 4th col only.

3) In my fifth col I want to enter date in this format only 'MM/DD/YYYY' and
should not allow any charcaters in it but Date.

Can some one help .

Tnx

Reply to this message...
 
    
Vagabond Software
"Paps" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address...
[Original message clipped]

You'll need to use TableStyles and DataGridColumnStyles. Here is an example of a DataGrid that might display File Name, File Size, and Last Modified date:

/* The DataGridTableStyle AllowSorting property
* overrides the DataGrid AllowSorting property. */

DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = dataSet.FileInfo.TableName;
style.AllowSorting = false;
style.AlternatingBackColor = Color.AliceBlue;
style.HeaderForeColor = Color.Blue;
style.DataGrid = this.dataGrid1;

/* This works for most text columns. I am displaying a a file name
* so I set the ReadOnly property to true. I also set the
* NullText property to get rid of the "null" that is displayed by
* default. */

DataGridTextBoxColumn textBoxColumn = new DataGridTextBoxColumn();
textBoxColumn.MappingName = "FileName";
textBoxColumn.Format = "";
textBoxColumn.FormatInfo = null;
textBoxColumn.HeaderText = "File Name";
textBoxColumn.NullText = "";
textBoxColumn.ReadOnly = true;
textBoxColumn.Width = 350;
style.GridColumnStyles.Add(textBoxColumn);

/* I use the Format property to display the File Size in KB
* rather than Bytes by adding that extra comma to the left
* of the period in my format string. */

DataGridTextBoxColumn numberColumn = new DataGridTextBoxColumn();
numberColumn.MappingName = "FileSize";
numberColumn.Alignment = HorizontalAlignment.Right;
numberColumn.Format = "#,###,. 'KB '";
numberColumn.FormatInfo = null;
numberColumn.HeaderText = "Size in KB";
numberColumn.NullText = "";
numberColumn.ReadOnly = true;
numberColumn.Width = 75;
style.GridColumnStyles.Add(numberColumn);

/* I use a custom date format in this Format property to display
* the date in a typically European style (e.g. 13 SEP 2004) and
* append the time in hours and minutes only. The 'tt' after the
* time will display 'am' or 'pm'. */

DataGridTextBoxColumn dateTimeColumn = new DataGridTextBoxColumn();
dateTimeColumn.MappingName = "LastModified";
dateTimeColumn.Alignment = HorizontalAlignment.Right;
dateTimeColumn.Format = "dd MMM yyyy hh:mm tt";
dateTimeColumn.FormatInfo = null;
dateTimeColumn.HeaderText = "Last Modified";
dateTimeColumn.NullText = "";
dateTimeColumn.ReadOnly = true;
dateTimeColumn.Width = 150;
style.GridColumnStyles.Add(dateTimeColumn);

/* Always add the the TableStyle to the DataGrid AFTER
* the ColumnStyles have been added to the TableStyle. */
this.dataGrid1.TableStyles.Add(style);
Reply to this message...
 
    
Paps (VIP)
"Vagabond Software" wrote:

[Original message clipped]

I tried adding the code with what you gave but I get all kinds of error:
Here is the code whic I put in my form Load event:

I have stuck a Datagrid on my form its called Datagrid1

DataGridTableStyle(style = New DataGridTableStyle())
'style.MappingName = DataSet.FileInfo.TableName
style.AllowSorting = False
style.AlternatingBackColor = Color.AliceBlue
style.HeaderForeColor = Color.Blue
style.DataGrid = this.dataGrid1

I get the error @
'DataGridTableStyle(Style
DatagridTableStyle is a Type only and cannot be used as an expression.
Am I missing out something here.

Tnx

Reply to this message...
 
    
Vagabond Software
"Paps" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address...
[Original message clipped]

I'm not that familiar Visual Basic.NET syntax, so double-check my syntax against other similar syntax used for similar declarations. For example:

Dim style As New DataGridTableStyle()

Also, it looks like you have the MappingName property assignment commented out. You'll need to map that to a TableName of an existing DataTable contained in your DataGrid1.DataSource.

Finally, this may simply be a typo in your post, but you say that you have a DataGrid control named "DataGrid1", but you assign the DataGrid property of the TableStyle to "this.dataGrid1" (with a small 'd').

Here is an example of using DataGridTableStyles with Visual Basic.NET from Microsoft:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtablestyleclassgridcolumnstylestopic.asp

I hope that helps.

- carl
Reply to this message...
 
 
System.Data.DataSet
System.Data.DataTable
System.Drawing.Color
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.TableStyle
System.Windows.Forms.DataGrid
System.Windows.Forms.DataGridTableStyle
System.Windows.Forms.DataGridTextBoxColumn
System.Windows.Forms.HorizontalAlignment




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification