Microsoft Cloud Authors: Yeshim Deniz, Janakiram MSV, John Katrick, David H Deans, Andreas Grabner

Related Topics: Microsoft Cloud, PowerBuilder

Microsoft Cloud: Article

DataWindow.NET How To: DataWindow Formatting

A simple but powerful way of formatting data in the presentation layer

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:


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.SetDataWindowBandColor (BandType.Detail, Color.Lavender)
dw_products.SetColumnFont(New Font("Tahoma", 8.0!))
dw_products.SetHeaderBackColor (Color.MidnightBlue)
dw_products.SetHeaderFont(New Font ("Tahoma", 8.0!, FontStyle.Bold))

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," + _
+ "," + _
Blue) + ")"
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.


Dim clickedobject As Sybase.
clickedobject = CType(sender,
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)
    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.


Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Long = &H112
Const SC_MOVE As Int32 = &HF010
   '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
End Sub

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.

Comments (11) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
monkfish 11/27/08 08:48:36 AM EST

thanks for the information. betsson iddaa

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

evden eve nakliyat Sohbet

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.


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
data interting are so smoth . We using connection ADO.net & ASP.Net security trust level default security level ( full trust level )

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'.
( In %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.Config
to change

***********Then I am facing a crucial problem ************
Required permissions cannot be acquired.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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:


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:


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.

@ThingsExpo Stories
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...