Archive

Posts Tagged ‘trick’

Delaying SelectedIndexChanged event of ComboBox in VB.NET WinForm

January 6th, 2010 Yuriy No comments

A standard situation - ComboBox control of VB.NET WinForm is populated with some data in Form_Load event and index is set to -1 so no item is selected:

Private Sub xfrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   xCombo.DataSource = GetSomeData()
   xCombo.SelectedIndex = -1
End Sub

Then, when user actually selects an item - SelectedIndexChanged event handler is called to perform action on the selected item:

Private Sub xCombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xCombo.SelectedIndexChanged
   PerformSomeAction(xCombo.SelectedValue)
End Sub

The problem with this approach is when data is bound in Form_Load - SelectedIndexChanged event handler is also called, and when SelectedIndex is set to -1, SelectedIndexChanged event is called again. Since we expect the SelectedIndexChanged to run only when user selects an item - this behavior may cause unwanted consequences.

The solution is Read more...

Categories: VB.NET Tags: ,

UltraWebGrid in OutlookGroupBy Mode: How to display custom aggregates (SUM, AVG, MIN, MAX) in GroupBy row

November 19th, 2009 Yuriy No comments

Last year I described a way to display accurate row count when grid in OutlookGroupBy mode has multiple sub-groups.

That solution requires custom counting function. Fortunately to display aggregates such as SUM, AVG, MIN and MAX UltraWebGrid has a built-in functionality in form of GroupByRowDescriptionMaskDefault property of DisplayLayout. It specifies the string to be displayed in every GroupBy row and can include following substitutes:

  • [caption] - will display GroupBy column header text
  • [value] - will display common to the group cell value
  • [count] - will display row count (does not work correctly with sub-groups)
  • [avg], [sum], [min], [max] - will display the aggregate for the column it's grouped by
  • [avg:ColumnKey], [sum:ColumnKey], [min:ColumnKey], [max:ColumnKey] - will display the aggregate for any other column, where ColumnKey is the key of the column

With this in mind in just a few simple steps we can make UltraWebGrid to display something like this:


Read more...

View real HTML source of a page

November 6th, 2009 Yuriy No comments

All browsers support "View page source" feature. But what it displays is source of the page as it was originally rendered by the server. In today's Web 2.0 world page content can change a thousand times after that. Client-side script, user input, AJAX calls can contribute to page update.

But one line of JavaScript code can show you a real up-to date page source. Type following in your browser address bar:

javascript:void prompt('HTML Source',document.documentElement.innerHTML)

Read more...

Categories: HTML/CSS, Javascript Tags: , , , ,