Entropy zero

January 15, 2012

Row #2, Col #4:What about a beer tonight?
Row #8, Col #3:Nope. I have a date 1am
Row #3, Col #1:I'm in, I'm in!
Row #3, Col #2:Fuck you Jon! You'll stay home!

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

End of the world

December 5, 2011

...enjoy it with some popcorn
Ooops! I completely forgot that today is December 21...!
Well. That's it. Honey! No need to wash the dishes anymore!

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Breakup

November 27, 2011

...see you next life.... next.... life... next...

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Me, Silverlight, ComboCheck-mutant and Frank Sinatra

November 24, 2011

I had the opportunity these days to use a lot fuck and shit words, and I am pretty gratefull for the universe for that. Tones of reasons. Particulary, for a mysterious one, I had to implement in Silverlight a custom filter for a List-based element.
So, let suppose that you are the lucky one who has to build a ComboBox, something like:

…and after selection is made, display something like:

…or, if a single item is checked:

…display the item itself:

I spent 6-7 hours on this issue, as it follows:

  • 1 hour search on the net for something usefull; usefull means, of course, a copy/paste routine. I didn’t find. It looks like I am the single human facing that problem.
  • 2 hours drinking coffe, smoking and thinking very deep on why?, why should I have to do this… Yep. I finally got the expected explanation: a fucking butterfly-effect. 1 million years ago a nice carnivor simply missed the gran-gran-gran…-gran-gran mother of one of my relatives, a blondie so called the mitocondrial Eve. Lucky me.
  • 3 hours implementing stuf for the Combo-Check-Box mutant above. Sorry for mentioning this one…
  • some time smoking again, just for fun and hoping that my ex will know somehow that I still smoke. Don’t know what this should be counted for, but I had fun on this.:)

Ok.
Some stuff explaining why this should not be possible are here:

http://www.jigar.net/articles/viewhtmlcontent328.aspx

http://msdn.microsoft.com/en-us/library/ms668604(v=vs.95).aspx

http://stackoverflow.com/questions/7999317/silverlight-combobox-with-checkboxes-items

I am not very sure that you are interested on how I did it, but just in case, here are the basic stuff.
If you are a female and you are still reading these, something is definitively wrong with that butterfly-effect :-)

1. Define a class implementing INotifyPropertyChanged

public class FilterOption: INotifyPropertyChanged
{
bool _use = false;
public bool use
{
get { return _use; }
set{
if (value != _use)
{
_use = value;
onPropertyChanged(this, “use”); }
}
}

public string _field;
public string field
{ get{ return _field;}
set{
if(value!=_field){
_field=value;
onPropertyChanged(this, “field”);
}
}
}

bool _show = true;
public bool show
{
get { return _show; }
set
{
if (_show != value)
{
_show = value;
onPropertyChanged(this, “show”);
}
}
}

public string abr { get; set; }

public event PropertyChangedEventHandler PropertyChanged;
private void onPropertyChanged(object sender, string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(sender,
new PropertyChangedEventArgs(propertyName));
if(propertyName.Equals(“show”))
PropertyChanged(sender,
new PropertyChangedEventArgs(“visibility”));
}
}

public Visibility visibility
{
get
{
return show ? Visibility.Visible : Visibility.Collapsed;
}
}
}

2. Define the ItemsSource

List FiltersOnTasks = new List();

private void SetFilters()
{
FiltersOnTasks = new List()
{
new FilterOption(){ use = true, field=”All”, abr=”All”, show=true },
new FilterOption(){ use = true, field=”Task name”, abr=”Tsk”, show=true },
new FilterOption(){ use = true, field=”Account”, abr=”Acc”, show=true },
new FilterOption(){ use = true, field=”Project”, abr=”Prj”, show=true },
new FilterOption(){ use = true, field=”Activity”, abr=”Act”, show=true },
new FilterOption(){ use = true, field=”Description”, abr=”Dsc”, show=true }
};
if (cmbFilter != null)
{
cmbFilter.ItemsSource = new ObservableCollection(FiltersOnTasks);
cmbFilter.SelectedIndex = 0;
}
}

3. XAML stuff

4. Combo-Check events

private void cmbFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//Important: nothing to do here :-)
}

private void chkFilter_Checked(object sender, RoutedEventArgs e)
{
SetFilterSelected(sender);
}

private void chkFilter_Unchecked(object sender, RoutedEventArgs e)
{
SetFilterSelected(sender);
}

private void SetFilterSelected(object sender)
{
if (sender is CheckBox)
{
string originalField = (sender as CheckBox).Tag.ToString();
bool origianlIsChecked = (sender as CheckBox).IsChecked != null ? (bool)(sender as CheckBox).IsChecked : false;
ObservableCollection list = (ObservableCollection)cmbFilter.ItemsSource;

string multipleFields = “”;
string lastCheckedField = “”;
int noChecked = 0;
for (int i = 1; i 0 ? “, ” + list[i].abr : list[i].abr);
noChecked++;
lastCheckedField = list[i].field;
}
}
else
{
if (list[i].use)
{
multipleFields += (multipleFields.Length > 0 ? “, ” + list[i].abr : list[i].abr);
noChecked++;
lastCheckedField = list[i].field;
}

}
}
if (noChecked == list.Count – 1)
multipleFields = “All”;
if (noChecked == 1)
multipleFields = lastCheckedField;
if (noChecked == 0)
{
multipleFields = “All”;
for (int i = 1; i < list.Count; i++)
list[i].use = true;
(sender as CheckBox).IsChecked = true;
}

list[0].field = multipleFields;
if (cmbFilter.SelectedIndex != 0)
cmbFilter.SelectedIndex = 0;
}
}

private void cmbFilter_DropDownOpened(object sender, EventArgs e)
{
((ObservableCollection)cmbFilter.ItemsSource)[0].show = false;
cmbFilter.UpdateLayout();
}

private void cmbFilter_DropDownClosed(object sender, EventArgs e)
{
((ObservableCollection)cmbFilter.ItemsSource)[0].show = true;
cmbFilter.SelectedIndex = 0;
cmbFilter.UpdateLayout();
}

5. Filtering stuff

….supposing that MyTask includes in definition some fields like account, project etc.
private List DoFilterText(List _data)
{
string filter = txtFilter.Text.ToLower().Trim();

bool useAccount = UseFilterOn(“acc”);
bool useProject = UseFilterOn(“prj”);
bool useTaskName = UseFilterOn(“tsk”);
bool useDescription = UseFilterOn(“dsc”);
bool useActivity= UseFilterOn(“act”);
if (useAccount || useProject || useTaskName || useDescription || useActivity)
{
List x = _data.Where(t =>
(useAccount && t.account.name.ToLower().IndexOf(filter) > -1) ||
(useProject && t.project.name.ToLower().IndexOf(filter) > -1) ||
(useActivity && t.activity.name.ToLower().IndexOf(filter) > -1) ||
(useDescription && t.description.ToLower().IndexOf(filter) > -1) ||
(useTaskName && t.taskname.ToLower().IndexOf(filter) > -1)).ToList();
return x;
}
return _data;
}

private bool UseFilterOn(string _abr)
{
FilterOption filter = FiltersOnTasks.Where(f => f.abr.ToLower().Equals(_abr.ToLower()) && f.use).FirstOrDefault();
return filter!=null && filter.use;
}

That’s it.
……..and what about Frank Sinatra? – will ask someone ( I suppose that a carnivore is still desperately looking for him…).
Well.
Just because he did it his way, no copy/paste there….
……..so what? – could answer that one, who surely was recently escaped from zoo.
Fuck you, Eve!

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Following the light

November 20, 2011

...so, this was all about...not funny at all...., next life I'll avoid triggers....

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Waiting for the Flood

November 19, 2011

We hire a Noah. Experience required.

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Roads

November 13, 2011

...she will return... she will return... she will return...

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Tough story

November 6, 2011

Hurry, back home! ....She will kill me!

…and, of course:

....I knew it...., I told you!

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

The thinker

November 5, 2011

I told you this morning: it stinks!...



….but let enjoy the day! Tomorrow will be worse.

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Shadows of lovers

October 30, 2011

Shadows of love

Shadow of lover #1: Miss you so much, Eva!

Shadow of lover #2: Pretty fair this way, Snake.

 

(c) marius09.wordpress.com
free counters
(c) 2009 marius09.wordpress.com

Follow

Get every new post delivered to your Inbox.