Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Monday, April 26, 2010

Code4Food #5: How to get specific XML nodes using Linq to XML ?

Hi, another question has been received from Bytes.com.

So the problem was that we needed to get all the tags “Error” from a specific XML without actually caring to much about where exactly in the XML tree is Error tag. And we need to do this using Linq to Xml.

So he got an xml like these:

<Users>
      <User>
           <FirstName>Tom</FirstName>
           <LastName>Won</LastName>
           <Error>Test 2</Error>
       </User>
      <User>
           <FirstName>Jim</FirstName>
           <LastName>Kim</LastName>
           <Error>Test 2</Error>
       </User>
       <Error>Test 3</Error>
</Users>

Now this problem isn't actually a problem at all. All you need is to use Linq to XML objects like XElement, XDocument, XNode, and so on (opposite thing to XmlElement, XmlDocument, and XmlNode). Actually you can do it without directly using Linq, by callings Descendants(XName name) method.

So this is the code that I’ve written to make this done.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;

namespace GetErrorTags.Linq2Xml
{
    static class Program
    {
        static void Main()
        {
            // Load the document into root XElement.
            // Remember in Linq you work with XDocument, XElement, XNode and not with XmlDocument, etc.
            XElement rootElement = XElement.Load("ErrorTags.xml");

            // without directly using Linq
            var errorTags = rootElement.Descendants("Error");

            Console.WriteLine("==============Without using Linq=========");

            foreach (XElement tagError in errorTags)
            {
                Console.WriteLine(tagError);
            }

            Console.ReadKey();

            // using Ling directly, we'll select only "Test 2" errors
            var linqErrorTags = rootElement.Descendants("Error").Where(element => element.Value.Equals("Test 2"));

            Console.WriteLine("==============Using Linq=========");

            foreach (XElement tagError in linqErrorTags)
            {
                Console.WriteLine(tagError);
            }

            Console.ReadKey();

        }
    }
}

And here is the output:

Download source

Thursday, April 22, 2010

Code4Food #4: How to change WinForms Treeview control image size?

Hi,

Today I visited Bytes.com and saw a question about Treeview.

Indeed how would one change ImageSize of a node ? So I had 15 free minutes and this is what I found.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TreeView.ImageSize
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            FillTreeView();
        }

        private void FillTreeView()
        {
            // Load the images in an ImageList.
            ImageList myImageList = new ImageList();
            myImageList.Images.Add(Image.FromFile("63vts4.jpg"));
            myImageList.Images.Add(Image.FromFile("ToDeleteIfNotSold.png"));
            
            // Change the size of the images.
            myImageList.ImageSize = new Size(50, 50);

            // Assign the ImageList to the TreeView.
            trvImages.ImageList = myImageList;
            trvImages.ItemHeight = 50;

            // Set the TreeView control's default image and selected image indexes.
            trvImages.ImageIndex = 0;
            trvImages.SelectedImageIndex = 1;

            // Create the root tree node.
            TreeNode rootNode = new TreeNode("CustomerList");

            TreeNode childNode1 = new TreeNode("Customer1");
            TreeNode childNode2 = new TreeNode("Customer2");

            // Add a main root tree node.
            trvImages.Nodes.Add(rootNode);
            trvImages.Nodes[0].Nodes.Add(childNode1);
            trvImages.Nodes[0].Nodes.Add(childNode2);
        }
    }
}

So the magic line was myImageList.ImageSize = new Size(50, 50); Here is the output and the code to download.

Download source code link

Wednesday, March 31, 2010

Tools I can’t imagine my dev life without #1: Ninite.com

Hi,

Last day of March and I want to start today this new series of posts where I’ll try to share with you some of the gems already there, but I suppose the majority of developers in the world don’t really know about.

So one of these gems is site Ninite.com.

Every time when I need to install a fresh version of Windows somewhere (and as a programmer I do this more than I would like to) and there is an internet connection I use Ninite installer to install all the software that is needed. It does have almost everything there, and the list is growing.

Once you’ve chosen the programs you’d like to install, it will generate an installer for you, and you should save it on your machine and download it. Now after you’ve downloaded it, run it and you will see something like these (it depends on the programs you’ve chosen).

After that, you’ll just need to wait while all of your programs will finish to install, and that’s all!

Awesome!!! Isn’t it?

Ideas, concerns, suggestions, tips & tricks – I’m waiting for all these. Take care.

Monday, October 12, 2009

Tips 003: Integrating Google Chrome with Delicious and Evernote and other cool tools

 

Hi,I use Google Chrome a lot and also I am already used with such beautiful tools which make my life easier and more structured :). One of those tools are Delicious bookmarks and Evernote notes. I use them almost everywhere.

I can talk hours about the worth of both of these tools, but I think about making a special series about useful tools in our life, I will definitely write about Evernote. So enough about that.

EVERNOTE

  • Now to test it, select something on a webpage and click on this bookmark.

  • So what do you need to do is just login into Evernote and everything selected will be saved as a note.

Delicious

 

Delicious in another cool app which will take care about your bookmarks. You can add tags, description, title to have the possibility to search through all your bookmarks using one of these attributes.

The annoying thing was that you would usually use the web site of the Delicious. What’s why I always liked the add-ons to Firefox and IE from Delicious it permitted me to use a shortcut to bookmark a website directly in Delicious system.

That’s why I missed it so much in Chrome.

  • Here you should find a very nice description how you can add 2 Delicious bookmarklets in Chrome. Just a simple drag-n-drop opperation will make it for you. Now you can see on your Chrome bookmarks bar these 2 buttons.

 

That’s the way to add some more functionality to Chrome while surfing the web with the great speed of JavaScript loading, that it’s offering. I love this browser and I think we could give it even more functionality.

If you know any other apps which can be used with Chrome as well or have any ideas, words to share, please leave a comment.

.

Sunday, September 20, 2009

Tip 002: Thumbnails not showing in Vista, Pictures folder

Hi, once in a while we all have this thing which seems to be a kinda sick problem, because nobody knows how to deal with it, and more nobody have ever seen or heard about things like that. There was this guy calling me and saying that he has this kinda crazy problem, he had a lot of photos, but the thumbnails didn't show up no matter what the poor guy was doing about it, just ordinary Vista icon for the image was shown (like mountains or something like that). First I was thinking that he has some hidden file where all the thumbnails info should be (something like Thumbnails.db in XP), which should deleted and than creating it one more time. But this wasn't the case. What it turned out to be is a simple option in Tools menu: Tools -> Folder Options -> View tab -> Advanced settings -> Files and Folders section, the check box "Always show icons, never thumbnails" should be unchecked. Because if it is checked, then you'll always see icons instead of thumbnails, and this refers not only to photos but to all kind of files like PDF or video files. So be aware of this option. See ya!

Friday, March 13, 2009

Tip 001: Missing desktop icons in Windows Vista

Hi, today something happened with my Vista, and all the icons (not just Recycle Bin or My Computer ) from the desktop were missing, however they were displayed in Windows Explorer Folder, as well as the sidebar was displayed normally. I tried to google this thing and I've found a simple solution. So this are the steps you need to follow:
  1. Open Desktop item in Windows Explorer.
  2. Go to menu Tools -> Folder Options -> Tab View -> Hidden files and folders -> Select "Show hidden files and folders" -> Click "Apply" and after that "Ok" (Note: If you don't see menu Tools, press ALT tab on your keyboard)
  3. Find the file desktop.ini in your desktop folder, if there are many of these delete them all.
  4. Restart your Vista (after this step your icons should be back)
  5. Repeat step 2 to Hide hidden files and folders
That's all you got to do.