Thursday, March 31, 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" >  
          <ContextMenu Name="ZoneIformationList" StaysOpen="true" Background="WhiteSmoke">  
               <MenuItem Header="Edit" Name="EditZoneInfoContextMenu" Click="EditZoneInfoContextMenu_Click" />  
               <MenuItem Header="Remove" Name="RemoveZoneInfoContextMenu" Click="RemoveZoneInfoContextMenu_Click" />  
               <GridViewColumn Header="Branch ID"  
            Width="80" DisplayMemberBinding="{Binding Path=ZoneBranchId}" />  
               <GridViewColumn Header="Building ID"  
            Width="80" DisplayMemberBinding="{Binding Path=ZoneBuildingId}" />  



Now you can set action on Click Event. consider EditZoneInfoContextMenu 

   private void EditZoneInfoContextMenu_Click(object sender, RoutedEventArgs e)  
           //Implement your method  
           private void FillZoneInformationField()  
       if (zonelistView.SelectedIndex > -1)  
         ObjEZoneSetup = (EZoneSetup) zonelistView.SelectedItem;  
         zoneIDtextBox.Text = ObjEZoneSetup.ZoneId;  
         zoneAisletextBox.Text = ObjEZoneSetup.ZoneAisle;  
         zonePositiontextBox.Text = ObjEZoneSetup.ZonePosition;  
         zoneTiretextBox.Text = ObjEZoneSetup.ZoneTire;  
         zoneInfotextBox.Text = ObjEZoneSetup.ZoneAdditionalInfo;  
         if (ObjEZoneSetup.ZoneStatus=='Y')  
           zoneActiveradioButton.IsChecked = true;  
         if (ObjEZoneSetup.ZoneStatus=='N')  
           zoneInactiveradioButton.IsChecked = true;  

Download the latest sample


Wednesday, March 23, 2011

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" >  
               <StackPanel Orientation="Horizontal">  
                 <TextBlock Text="{Binding ZoneBranchId}" Width="60"/>  
                   <TextBlock Text="|"/>  
                 <TextBlock Text="{Binding ZoneBranchName}" Width="60"/>  

==========Your UI Code for Load ComboBox:=========

 private void LoadBranchIDComboBox()  
 listOfZone = ObjBZoneSetup.GetAllBranchID();  
 foreach (EZoneSetup floorSetupObj in listOfZone)  
 ZoneBranchIDcomboBox.ItemsSource = listOfZone;  

=============== Business Logic============
 public List GetAllBranchID()  
 List listOfZoneBranchID = ObjZoneDAL.GetAllBranchID();  
 return listOfZoneBranchID;  

============== GateWay:=============
 public List GetAllBranchID()  
 List listOfBranchID = new List();  
 foreach (var ZoneSetup in objDataContext.SP_GET_BRANCH_NAME())  
 EZoneSetup eZoneSetupobj = new EZoneSetup();  
 eZoneSetupobj.ZoneBranchId = ZoneSetup.WI_ID;  
 eZoneSetupobj.ZoneBranchName = ZoneSetup.WI_NAME;  
 catch (Exception exception)  
 throw exception;  
 return listOfBranchID;  


Wednesday, March 9, 2011

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)



In Get generatenumber(ticketObj) method after generating the number from substring it add string again for every new number.

public List GetGenerateNumber(Ticket ticketObj)
List list=new List();

int firstNumber = ticketObj.LasetTicketNo;
int secondNumber = ticketObj.QuantiryOfTicket;
int result = firstNumber + secondNumber;
string ticketNumber;

for (int count = firstNumber+1; count <= result; count++)
Ticket ticketObjTosend = new Ticket();
//ticketObjTosend.EncriptedTicket += "CA";
ticketObj.NewTicketNo = Convert.ToInt32(count);

ticketObjTosend.NewTicketNo =ticketObj.NewTicketNo;
ticketNumber = "CA";
ticketNumber += Convert.ToString(ticketObjTosend.NewTicketNo);

ticketObjTosend.EncriptedTicket = ticketNumber;

ticketObjTosend.TicketDuration = ticketObj.TicketDuration;
ticketObjTosend.TicketCreationdate = ticketObj.TicketCreationdate;


return list;


Thursday, March 3, 2011

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)  
       MessageBox.Show("Please select item for remove from the list");  

Download the Latest Sample


Wednesday, March 2, 2011

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" >
<GridView AllowsColumnReorder="True">

<GridViewColumn DisplayMemberBinding="{Binding Path=VendorId}" Header="Vendor ID" Width="90"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=VendorName}" Header="Vendor Name" Width="90"/>

vfpoledeb.1 provider is not registered on the local machine

Have u Install VFP Ole DB Provider in your System ? If No then Please Install it from following link.