Posts Tagged: DoUNo


22
Feb 09

DoUNo: ListView_ItemSelectionChangedEvent and MultiSelect

Today, I was trying to customise ListViewControl by playing with the item drawn event, thats when I came across this peculiar stuff.

In ListView, if you have subscribed for the ItemSelectionChangedEvent,the event will not be raised, if you select the same item more than once provided the ListView.MultiSelect = false;  Shhh. Quite difficult to understand, isn’t it ??

Ok. An example, Lets consider that  we have a list view control with two items, foo and bar. Also consider that we have subscribed for the ItemSelectionChangedEvent and the ListView’s MultiSelect is true. Now if you run the application keeping a break point in the ItemSelectionChangedEventHandler and if you select the item foo again and again the control will break. On the other hand, if your ListView’s MultiSelect is false, the control won’t hit the break point. Which means that the event will not be raised.


17
Feb 09

DoUNo: Reading Console’s text in C#

Its really simple to read a console’s text (contents) in C#. This can be done using the Console.In.ReadLine() method. The Console and the Console.In classes exposes a loads of methods that are really handy. Here is a small snippet that tries to print the directories in blue color and the others in default color in console when you type dir.

string aConsoleReadLine = null;
ConsoleColor aDefaultConsoleColor = Console.ForegroundColor;
while ((aConsoleReadLine = Console.In.ReadLine()) != null)  //Reading the text from the console and storing it in a local variable
{
  if (aConsoleReadLine.Contains("<DIR>"))  //Check if it is a directory
  {
    Console.ForegroundColor = ConsoleColor.Blue;
  }
  else
  {
    Console.ForegroundColor = aDefaultConsoleColor;
  }
  Console.WriteLine(string.Format("{0}", aConsoleReadLine));
}

To run the above mentioned snippet, create a console app and put this snippet in your main method. Then, open up command prompt. In the command prompt type dir | <your_built_exe>.exe. We use | so that we can get the output to our program.


4
Feb 09

DoUNo: Is operator overloading possible in structs ??

Yeah. One can overload operators in a structure (C#). Syntaxes are similar to that of class operator overloading, except for that fact that we need to operate on struct variables and not on class objects (obvious isn’t it ??).

For newbies — struct is of value type (stored in stacks) and classes are of reference types (stored in heaps)


4
Feb 09

DoUNo: Operator overloading in Size and Point

You can add two Size or Point members directly using the + key. Did you know that ?? You can even do -, == and != on these memebers. You cannot do * or / on them thou’. If  you find anyother class / struct in C# that enables operator overloading, you can add it to the above it. Hope you find this useful.


3
Feb 09

DoUNo: ListViewItems in C#

When you create a ListViewItem in C#, it automatically creates a ListViewSubItem for it and the ListViewItem.SubItem[0] is the ListViewItem


i.e, the default value of ListViewItem is the value of ListViewItem at SubItems[0] 
 

You can find more about ListViewItems in http://codelog.blogial.com/2008/07/18/using-listview-control/ 

Refer to http://stackoverflow.com/questions/502782/automatic-creation-of-listviewsubitems to know my experiences with the ListViewControl.