Skip to main content

Posts

Showing posts from March, 2011

WPF Contextmenu For ListView item

If we want to use context menu in WPF Listview. Then we have to done 2 steps: Bind your Listview for Contex Menu: <ListView Height="136" Background="#FFDBF3F3" BorderBrush="#FF40C01D" HorizontalAlignment="Left" Margin="6,6,0,0" Name="zonelistView" VerticalAlignment="Top" Width="722" > <ListView.ContextMenu> <ContextMenu Name="ZoneIformationList" StaysOpen="true" Background="WhiteSmoke"> <ContextMenu.BitmapEffect> <BitmapEffectGroup/> </ContextMenu.BitmapEffect> <MenuItem Header="Edit" Name="EditZoneInfoContextMenu" Click="EditZoneInfoContextMenu_Click" /> <MenuItem Header="Remove" Name="RemoveZoneInfoContextMenu" Click="RemoveZoneInfoContextMenu_Click"

WPF Multicolumn ComboBox

In WPF Multicolumn ComboBox we can easily complete it By the following procedure: Modify your Combobox maml as following: ================XAML  Binding =============== <ComboBox Height="23" HorizontalAlignment="Left" Margin="87,7,0,0" Name="ZoneBranchIDcomboBox" VerticalAlignment="Top" Width="160" > <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding ZoneBranchId}" Width="60"/> <TextBlock Text="|"/> <TextBlock Text="{Binding ZoneBranchName}" Width="60"/> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> ==========Your UI Code for Load ComboBox:========= private voi

Substring and add String in WPF

hi all, For our application sometimes we need substring a string. Hare i give example in which it take a string from a text field and then substring it for perticular operation. private void GenerateTicket() { string ticketNumber = lastTicketNumbertextBox.Text; string substring = ""; substring = ticketNumber.Substring(2, 8); ticketObj.LasetTicketNo = Convert.ToInt32(substring); ticketObj.QuantiryOfTicket = Convert.ToInt32(ticketQuantitytextBox.Text); ticketObj.TicketDuration = Convert.ToInt32(ticketTimeDurationtextBox.Text); ticketObj.TicketCreationdate = Convert.ToDateTime(ticketGeneratordatePicker.Text); list = ticketManager.GetGenerateNumber(ticketObj); ticketObj.ListOfTicket = list; foreach (Ticket ticketObj1 in list) { { ticketlistView.Items.Add(ticketObj1); } } } In Get generatenumber(ticketObj) method after generating the number from substring it add string again for every new number. public List GetGenerateNumber(Ticket ticketObj)

WPF Delete Selected Item From Listview

we often need to delete item from Listview. You have to use context menu for perform delete operation. then on your delete event just write: private void ticketRemovebutton_Click(object sender, RoutedEventArgs e) { if (ticketlistView.SelectedItem != null) { ticketlistView.Items.RemoveAt(ticketlistView.Items.IndexOf(ticketlistView.SelectedItem)); } else { MessageBox.Show("Please select item for remove from the list"); } } Download the Latest Sample Enjoy....!!

How to Get Machine IP Address

Sometimes we need to get the IP Address of the current PC. Under a Event we can get the IP address Easily by using the Code: string myHost = System.Net.Dns.GetHostName();             string myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[1].ToString();             MessageBox.Show("My PC Name : "+myHost + "\nMy IP Address : " + myIP);

WPF add listview column binding in XAML

some time we fall in confused that how to we will add Column in Listview it's quite Easy: < ListView Height ="91" HorizontalAlignment ="Left"     Margin ="6,6,0,0" Name ="ticketlistView" VerticalAlignment ="Top" Width ="560" > < ListView.View > < GridView AllowsColumnReorder ="True"> < GridViewColumn DisplayMemberBinding ="{ Binding Path =VendorId}" Header ="Vendor ID" Width ="90"/> < GridViewColumn DisplayMemberBinding ="{ Binding Path =VendorName}" Header ="Vendor Name" Width ="90"/> </ GridView > </ ListView.View > </ ListView >