Tag Archives: winform

Serving image from ASP.NET MSChart to external applications via WebService

I have an existing ASP.NET application that uses Microsoft Charting control for .NET. I created a CCharting class that hold several methods related to getting data for the chart, applying chart appearance etc. Main method of that class is

Public Sub DrawChart(ByVal i_omsChart As Chart, ByVal i_iChartWidth As Integer, ByVal i_iChartHeight As Integer)

As a 1st parameter it accepts actual chart control from the page, 2nd and 3rd are chart width and height. The method then gets the data for the chart, binds chart to that data, applies chart appearance (colors, series, axises) etc. So drawing a chart is a simple as instantiating the class and calling the method:

Dim oCharting As New CCharting
CCharting.DrawChart(xmsChart,500,300)

where xmsChart is a chart control from HTML markup of the page. The result is displayed on the page:

But now I needed to give access to that chart to external applications, that do not have access neither to chart data nor to Microsoft charting control, may run under different OS’s, be Web apps or not. Continue reading →

Delaying SelectedIndexChanged event of ComboBox in VB.NET WinForm

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 Continue reading →