Tuesday, November 21, 2006

VB COLOR CONVERSION


What can we do with a VBColor in C#? For example, let's take vbRed = 255.
In C# we can choose:
Color.FromArgb(int red, int green, int blue)
Color.FromKnownColor(System.Drawing.KnownColor color)
Color.FromName(string name)
or an already named color.
These do not help.
However, if we convert the decimal 255 to hex, we get: 0000FF, a BGR value. This can be easily converted into an RGB value, and giving this string to Color.FromName("#FF0000"), we get the color we wanted from the first place.

exp: 12615935(dec) = C080FF(hex) in BGR = FF80C0(hex) in RGB
"#FF80C0" - gives in C# the color we wanted.

Friday, November 03, 2006

MSSQL RESULT CACHING

Strange issue:I have an sql user-function, which returns the result of a select statement, thus, a table. The server never stopped, and we modified something else in our database, and so, there should be a column with modified values in that table.The problem is, that while running the select statement of the function returns the expected result, calling the function by: select * from functionName ... returns the table with the original column values.From my opinion, this should only happen, if there is a result caching for user-defined-functions!
And it is the reason. For all stored procedures and function there is a result caching.The cache can be cleared with:

DBCC FREEPROCCACHE

Monday, October 30, 2006

HEXAGONAL PANEL?


What if, we need a panel, that would hold two controls in the following manner:
(the panel is the red container, and it has to be hexagonal, holding two input fields, the way it is drawn)

Well, hexagonal panels do not exist, but we can simulate them by changing two style attributes of the second control.
Let
ctrl2.Style.Add("POSITION","absolute");
ctrl2.Style.Add("RIGHT","20px");
and so, we will obtain the following:


The panel still holds both controls, even if it is not so obvious any more.

Thursday, October 26, 2006

GOOD TO KNOW!


All controls, that require their state to be maintained in ViewState should be initialized (created) before the LoadViewstate event.

Thanks, Attila!

Wednesday, October 25, 2006

WHEN IT DOESN'T WORK - element.setAttribute(...) - javascript


Examples for using element.setAttribute("att_name","att_value") in javascript:
element.setAttribute("src","../Pictures/x.jpg"); // OK, it works.
element.setAttribute("style","cursor: hand;"); // NOT OK, it doesn't work.

So, when trying to add style attributes to elements in javascript, instead of the previous line use:
element.style.setAttribute("cursor","hand",0); // OK, it works.

Thursday, October 19, 2006

MANIPULATING DATAGRIDS IN JAVASCRIPT


Manipulating DropDownLists for example, in javascript, is similar to manipulating ListBoxes. However, if we want to add/remove items to/from a DataGrid, we have to act somewhat else. A DataGrid control is rendered as a Table with several TableRows, and TableColumns.

Adding a row to a grid with 2 columns:

var lastRow = grid.rows.length;
var row = grid.insertRow(lastRow);

var cellLeft = row.insertCell(0);
var textNode = document.createTextNode("col1/rowx");
cellLeft.appendChild(textNode);

var cellRight = row.insertCell(0);
var textNode2 = document.createTextNode("col2/rowx");
cellRight.appendChild(textNode2);

Deleting a row from the same grid:

grid.deleteRow(index); // 1<= index < grid.rows.length - if the grid has a header.

Thursday, October 05, 2006

MANIPULATING LISTBOXES IN JAVASCRIPT


Ever occured the problem of moving elements from one ListBox to another? It can be done easily on server side, but what if you could get rid of those annoying postbacks? Here's a tip:

An asp ListBox renders as follows:

<select ...>
<option value="aaaaa">aaaaa</option>
<option value="bbbb">bbbb</option>
<option value="ccc">ccc</option>
...
</select>

The following code snippets might be useful in such case:

1. you need to have an array with all elements of the first ListBox
var myListbox = document.getElementById(lb1Id); // lb1Id is the ClientId of the control
var myListboxOptions = myListbox.getElementsByTagName("option");

2. need a clone of the original ListBox and a clone of all options
var cloneOfMyListbox = myListbox.cloneNode(true);
var cloneOfMyListboxOptions = cloneOfMyListbox.getElementsByTagName("option");

3. you need the other ListBox
var otherListbox = document.getElementById(lb2Id); //lb2Id is the ClientId of the second control

4. and the mechanisms for moving certain elements from the first ListBox to the second one
otherListbox.appendChild(cloneOfMyListboxOptions[index].cloneNode(true)); // add element to the second control
myListbox.remove(index); // remove the element on the specific index from the first control

Friday, September 01, 2006

TRIM IN JAVASCRIPT


str - the string
str.replace(/^\s*\s*$/g,""); - the trimmed string

Wednesday, August 02, 2006

<tagname> - egy post-ban

Az előbbi post-nál nagy gondban voltam, mert a <tagname>-t nem szövegként kezelte le ez a szerkesztő, hanem html/xml tagként, így eltűnt. Ezért gondoltam, hogy felteszek ide egy listát a kódokkal, hogy máskor ne kelljen Google-ezzek ilyesmi miatt.

< = & l t ;
> = & g t ;

P.S. a kódokat nyilván szóköz nélkül kell használni.

HTC


A HTC file is nothing but an HTML file, saved with a .htc extension. It contains scripts and a set of HTC-specific custom elements, that define the component.

Objects:
document - the HTML document in a given browser window
PUBLIC: ATTACH - binds a function to an event
PUBLIC: COMPONENT - identifies the content of the file as HTC
PUBLIC: DEFAULTS - sets default properties for an HTC
PUBLIC: EVENT - defines an event
PUBLIC: METHOD - defines a method
PUBLIC: PROPERTY - defines a property of the HTC
element - returns a reference to the tag in the primary document, to which the behavior is attached

exp.
attaching behavior to a simple asp TextBox:
TextBox _myTextBox;
...
_myTextBox.Style.Add("behavior","url(myhtcfile.htc)");

where the HTC file should look like this:
<PUBLIC: COMPONENT>
<PUBLIC: PROPERTY name="propertyName" />
<PUBLIC: ATTACH event="eventName" handler="MyEventHandler"/>
...
<SCRIPT language="JScript">
function MyEventHandler()
{ ... }
</SCRIPT>
</PUBLIC: COMPONENT>

and the file name should be:
myhtcfile.htc

Friday, July 14, 2006

SAVE A .GIF WITH TRANSPARENT BACKGROUND - in Ms Expression


Need to create a picture with transparent background?
This is the way to do it, using Microsoft Expression:

1. Open a new file in Pixel Layer
2. Choose the Magic Eraser Tool, then click on the paper
3. Do the drawing
4. Save the file by Export: Export » to Image Format » gif » Save Alpha Channel

The background will be transparent.

Tuesday, July 11, 2006

EXCEL SHEET ÜRES SORAINAK KITÖRLÉSE - VBA makró


Ha automatikusan hozol létre Excel Sheeteket, nem tuhatod, hogy hány sorra is lesz pontosan szükség => jobb, ha minél többet adsz hozzá az elején. Ellenben, a sok üres sor gondot okozhat processzáláskor, így ez a makró kiörli az "üresnek tekintetteket". Hogy ki melyik sort tekinti üresnek, a feltétel határozza meg.

Sub RemoveEmptyRowsFromASpecificSheet()
Dim rng As String
rng = ""
totalrows = Sheets("SpecificSheet").UsedRange.Rows.Count
For Row = 1 To totalrows Step 1
If Sheets("SpecificSheet").UsedRange.Cells(Row, 1).Value = "" Then
rng = "A" + CStr(Row) + ":P5000"
Exit For
End If
Next Row
Sheets("SpecificSheet").Range(rng).EntireRow.Delete
End Sub