|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS Tips & Tricks
DataWindow.NET How To: DataWindow Formatting
A simple but powerful way of formatting data in the presentation layer
By: Bruce Armstrong
Feb. 3, 2006 02:00 PM
Digg This!
Page 2 of 4
« previous page
next page »
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() 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 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) 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") 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 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.
Subclassed DataWindow Control WndProc
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Page 2 of 4 « previous page next page »
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||||||