| By Bruce Armstrong | Article Rating: |
|
| February 3, 2006 02:00 PM EST | Reads: |
27,680 |
The FormatGridWithBothTableAndColumnStyles method (only an excerpt is shown below) uses both of those approaches and also defines a series of DataGridTextBoxColumn objects to handle the formatting of specific columns. The DataGridTextBoxColumn objects are then assigned to the DataGridTableStyle before it's applied to the DataGrid:
FormatGridWithBothTableAndColumnStyles
Dim grdColStyle1 As New DataGridTextBoxColumn()
With grdColStyle1
.HeaderText = "ID"
.MappingName = "ProductID"
.Width = 50
End With
.
.
.
grdTableStyle1.GridColumnStyles.AddRange _
(New DataGridColumnStyle() _
{grdColStyle1, grdColStyle2, grdColStyle3, grdColStyle4})
Now, the most obvious thing to do if you want generic formatting of a DataWindow is to set up that formatting in the DataWindow object to begin with. However, the point of this "how to" is to show how we can do it through code, so we'll do that instead.
Some of the formatting of the DataWindow we'll do by setting the properties of the control itself:
dw_products.BorderStyle = Sybase.DataWindow.DataWindowBorderStyle.None
dw_products.TitleBar = True
dw_products.Text = "Northwind Products"
We'll implement others by doing SetProperty calls on the underlying DataWindow object. I've subclassed the DataWindow control and added methods for setting a number of the font and color properties.
dw_products.SetDataWindowColor(Color.GhostWhite)
dw_products.SetDataWindowBandColor (BandType.Detail, Color.Lavender)
dw_products.SetColumnFont(New Font("Tahoma", 8.0!))
dw_products.SetColumnBackColor(Color.GhostWhite)
dw_products.SetColumnColor(Color.MidnightBlue)
dw_products.SetHeaderBackColor (Color.MidnightBlue)
dw_products.SetHeaderFont(New Font ("Tahoma", 8.0!, FontStyle.Bold))
dw_products.SetHeaderColor(Color.Lavender)
dw_products.SetColumnWidth(100)
dw_products.SetRowHeight(15)
Note that there are a couple of properties that the DataGrid lets you set that the DataWindow doesn't give us any control over. Specifically with regard to this demo, we can't set the font or colors for the caption (the DataWindow control title area). I imagine that we might be able to do it by overriding the painting of the title bar in the subclassed control, but I'm not interested enough in those particular attributes to try it. The other properties of interest in this particular example are the fore and back colors for the band indicating the selected row(s) and color of the grid lines.
To get the same effect as the DataGridTextBoxColumn object, we just set the properties for individual columns of the DataWindow object:
dw_products.SetProperty("productid.width", "50")
dw_products.SetProperty("unitprice.width", "75")
dw_products.SetProperty("unitsinstock.width", "75")
Note that the DataGrid doesn't offer much manipulation of the column-level properties. For example, the DataGridTextBoxColumn object doesn't provide access to color attributes - so you can't set the color for individual columns. There are ways to overcome this, but they involve a great deal more effort than a SetProperty call. For more information, you can refer to George Shephard's Windows Forms FAQ for DataGrid controls at www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx
Many of the features listed in the FAQ that take some effort to implement (setting row height, outthought rows, displaying a data-driven combobox or other edit controls (checkbox)) are simply a matter of setting a property or adding an edit style to the DataWindow object.
Also note that once you start defining DataGridTextBoxColumn objects, you have to create one for each column you want to display in the DataGrid regardless of whether you want to change its formatting. If you specify DataGridTextBoxColumn objects for some - but not all - of the columns in the DataSet, only the columns that have a DataGridTextBoxColumn object defined for them will display. (Shepard's FAQ offers a workaround for this particular behavior). With the DataWindow control, you can alter the formatting for any number of columns without affecting the visibility of the other columns in the result set.
However, the main advantage of the DataWindow over the DataGrid with regard to formatting is that many of the DataWindow object properties accept expressions that can be used to determine their value. Those expressions can use functions that determine state information for the control, or refer to data in the control. This lets you specify formatting not just for individual columns, but for individual cells. For example, in the FormatDataWindowTableStyle method if there are no units in stock, we set the color of the text in the unitsinstock column to red as follows:
Dim modify As String
modify = dw_products.GetRGB
(Color.MidnightBlue) + _
"~tif ( unitsinstock < 5," + _
dw_products.GetRGB(Color.Red)
+ "," + _
dw_products.GetRGB(Color.Midnight
Blue) + ")"
dw_products.SetProperty("units
instock.Color", modify)
For a DataWindow object property expression, the default value is followed by a tab character ("~t") and then the expression used to derive the value.
Now let's take a look at some of the code we had to implement to give the DataWindow control a bit more of a DataGrid look-and-feel. One item of code was added to the Click event handler for the DataWindow control in the form (see below). It sets the row to selected if the user clicks on the first column of the row. Note the SelectRow(0,False) call, which deselects all previously selected rows. If we wanted to allow multi-selection, we would check the selected status of the current row and toggle it rather than clearing the selection status of all rows.
dw_products_Click
Dim clickedobject As Sybase.
DataWindow.ObjectAtPointer
clickedobject = CType(sender,
DataWindowControl).ObjectUnderMouse()
Select Case clickedobject.Band.Type
Case Sybase.DataWindow.BandType.Detail
CType(sender, DataWindowControl).SelectRow(0, False)
If clickedobject.RowNumber > 0 Then
If clickedobject.Gob.Name = "c_1" Then
CType(sender, DataWindowControl)
.SelectRow(clickedobject.
RowNumber, True)
End If
End If
End Select
Subclassed DataWindow Control
The remainder of the additional code is in our subclass of the DataWindow control. The first thing we did is override the WndProc method. One problem with the DataWindow control is that if you make the title bar visible, it also makes the control moveable. To prevent the control from being moved, we monitor for the WM_SYSCOMMAND message (which is passed to WndProc) and determine if a SC_MOVE is being attempted. If so, we return from the overloaded method without calling the ancestor - otherwise we call the ancestor so normal processing can continue.
WndProc
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Long = &H112
Const SC_MOVE As Int32 = &HF010
If m.Msg = WM_SYSCOMMAND Then
'The four low order bits of wParam are used internally by Windows,
'so we need to do a bitwise and with FFF0 to get the real value.
If ((m.WParam.ToInt32 And &HFFF0) = SC_MOVE) Then Exit Sub
End If
MyBase.WndProc(m)
End Sub
Published February 3, 2006 Reads 27,680
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.
![]() |
monkfish 11/27/08 08:48:36 AM EST | |||
![]() |
SohbetGor 11/17/08 09:42:36 AM EST | |||
thanks you... |
||||
![]() |
Qarisma 11/05/08 05:54:22 PM EST | |||
But real Güzeş Site head turn before such excellent Sitelent see _______________ |
||||
![]() |
alvin 07/23/08 08:39:54 PM EDT | |||
how can i change the highlight color of selected row? the default is blue which looks heavy. |
||||
![]() |
Bruce Armstrong 12/10/07 12:27:42 PM EST | |||
I'd suggest posting your question in Sybase's DataWindow.Net forum. http://www.sybase.com/detail?id=1031119 It would be much easier to address there. |
||||
![]() |
Praveen 12/10/07 02:02:28 AM EST | |||
Sir , We are using Datawindow.net 2.0[Trail] in VS2005 with ASP.Net 2.0 & C#.Net . Using WebDatawindow.net in ASP.Net data retrieving and also For security problem most of developer suggests that 'medium trust'and also our webserver support only medium trust.So we are changing Security policy to 'medium'. ***********Then I am facing a crucial problem ************ Exception Details: System.Security.Policy.PolicyException: Required permissions cannot be acquired. How can overcome to in this problem . If you have any solution ... pls forward me ... |
||||
![]() |
Bruce Armstrong 11/14/07 07:09:07 AM EST | |||
I'd suggest posting your question in Sybase's DataWindow.Net forum: http://www.sybase.com/detail?id=1031119 It would be much easier to address there. |
||||
![]() |
Atif Riaz 11/14/07 01:51:39 AM EST | |||
Hey this is atif i have read your articles they were really help full. what i am trying is that i am using data window 2.0 in Dotnet now i want any CSS file like we do it for html or asp pages i want to define CSS file from where i can formate the report made in Data Window automatically. I need your help? |
||||
![]() |
Bruce Armstrong 02/07/06 03:58:48 PM EST | |||
If you can't find it here, check the Sybase CodeXchange site. I loaded it there as well: http://datawindownet.codexchange.sybase.com/servlets/ProjectDocumentList... |
||||
![]() |
Mike 02/07/06 02:58:03 PM EST | |||
Where is an arcticle code? |
||||
![]() |
SYS-CON Australia News Desk 02/03/06 01:45:59 PM EST | |||
In this article, we're going to look at how DataWindow.NET technology is a simpler but more powerful way of formatting data in the presentation layer. We'll be taking a sample application provided by Microsoft for .NET and implementing it using DataWindow.NET technology. |
||||
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications






























