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" >  
  <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" />  
           </ContextMenu>  
  </ListView.ContextMenu>  
          <ListView.View>  
             <GridView>  
               <GridViewColumn Header="Branch ID"  
            Width="80" DisplayMemberBinding="{Binding Path=ZoneBranchId}" />  
               <GridViewColumn Header="Building ID"  
            Width="80" DisplayMemberBinding="{Binding Path=ZoneBuildingId}" />  
             </GridView>  
          </ListView.View>  
   </ListView>  

 

     
         

Now you can set action on Click Event. consider EditZoneInfoContextMenu 



   private void EditZoneInfoContextMenu_Click(object sender, RoutedEventArgs e)  
     {  
       FillZoneInformationField();  
     }  
           //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;  
         }  
         zonelistView.Items.Remove(zonelistView.SelectedItem);  
       }  
     }  




Download the latest sample

Enjoy.....!


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" >  
           <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 void LoadBranchIDComboBox()  
 {  
 ZoneBranchIDcomboBox.Items.Clear();  
 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();  
 try  
 {  
 foreach (var ZoneSetup in objDataContext.SP_GET_BRANCH_NAME())  
 {  
 EZoneSetup eZoneSetupobj = new EZoneSetup();  
 eZoneSetupobj.ZoneBranchId = ZoneSetup.WI_ID;  
 eZoneSetupobj.ZoneBranchName = ZoneSetup.WI_NAME;  
 listOfBranchID.Add(eZoneSetupobj);  
 }  
 }  
 catch (Exception exception)  
 {  
 throw exception;  
 }  
 return listOfBranchID;  
 }  

Enjoy....

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)
{

{
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)
{
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;

list.Add(ticketObjTosend);


}
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)  
      {  
       ticketlistView.Items.RemoveAt(ticketlistView.Items.IndexOf(ticketlistView.SelectedItem));  
      }  
    else  
      {  
       MessageBox.Show("Please select item for remove from the list");  
      }  
 }  









Download the Latest Sample

Enjoy....!!

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" >
<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>

SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...