Welcome!

Microsoft Cloud Authors: Lori MacVittie, Elizabeth White, Yeshim Deniz, Serafima Al, Janakiram MSV

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:

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

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...

Sohbet

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.
thanks

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
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
to
)

***********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:

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.

@ThingsExpo Stories
Announcing Poland #DigitalTransformation Pavilion
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
CloudEXPO | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
"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.
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
In past @ThingsExpo presentations, Joseph di Paolantonio has explored how various Internet of Things (IoT) and data management and analytics (DMA) solution spaces will come together as sensor analytics ecosystems. This year, in his session at @ThingsExpo, Joseph di Paolantonio from DataArchon, added the numerous Transportation areas, from autonomous vehicles to “Uber for containers.” While IoT data in any one area of Transportation will have a huge impact in that area, combining sensor analytic...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
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 ...
I think DevOps is now a rambunctious teenager - it's starting to get a mind of its own, wanting to get its own things but it still needs some adult supervision," explained Thomas Hooker, VP of marketing at CollabNet, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.