Monday, March 22, 2010

Me.Controls in WPF

Use the parent control children property.
below Main is my grid name which contains saveral controls (some of them are textboxes)

For Each Control As Control In Main.Children
If Control.GetType.ToString() = "System.Windows.Controls.TextBox" Then
Control.BorderBrush = Brushes.Gray
End If
Next

Sunday, March 14, 2010

T-SQL Loop (Fetch)

DECLARE @Event_ID int

DECLARE my_cursor CURSOR FOR
SELECT Event_ID FROM ITS_CALENDAR_EVENTS_LIST
WHERE EVENT_SA_Flag = 1

OPEN my_cursor

FETCH NEXT FROM my_cursor
INTO @Event_ID

WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO ITS_CALENDAR_EVENTS_TO_FLAGS (Event_ID, Event_Flag_ID)
VALUES (@Event_ID, 1)

FETCH NEXT FROM my_cursor
INTO @Event_ID
END

CLOSE my_cursor
DEALLOCATE my_cursor

Monday, March 8, 2010

Assign datatable to combobox WPF

.XAMAL Code
ComboBox Height="23" HorizontalAlignment="Left" Margin="6,90,0,0" Name="cmbPlaceOfWork" VerticalAlignment="Top" Width="191"
(put xamal tags, < before ComboBox and /> after "191")

.XAMAL.vb Code
01-Imports System.ComponentModel

02-Private Sub FillPlaceOfWork()

Me.cmbPlaceOfWork.ItemsSource = (CType(DBRelated.GetDataTable("Select CME, FirstName As FullName From Personnel"), IListSource)).GetList()
Me.cmbPlaceOfWork.DisplayMemberPath = "FullName"
Me.cmbPlaceOfWork.SelectedValuePath = "CME"

End Sub

INFO: DBRelated.GetDataTable("Select CME, FirstName As FullName From Personnel")
The above function is from my class DBRelated and its just returning a datatable (i am using access as my backend db)

03-Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSearch.Click
MessageBox.Show(Me.cmbPlaceOfWork.SelectedValue)
End Sub

Select some value and you can get the SelectedValue by the above property of combobox.

Application/AppDirectory Path WPF

Full exe path
System.Reflection.Assembly.GetExecutingAssembly().Location

Directory from exe file executed
AppDomain.CurrentDomain.BaseDirectory

Tuesday, March 2, 2010

Change label color programmatically in WPF

Rather than System.Drawing.Color enum
use System.Windows.Media.Brushes

Me.lblDentist.Foreground = Brushes.Blue

Exit a WPF application

Application.Current.Shutdown()