Search This Blog

Thursday, May 14, 2015

Find last row Telerik RadGridView

Telerik > RadGridView > Find last row
GridViewRowInfo lastRow = radGridView.Rows[radGridView.Rows.Count - 1];
lastRow.IsSelected = true;






Wednesday, May 13, 2015

C# Generic Interface Example

C# > Generics > Generic Interface 

Example


class Serializer1 { public string Name { get; set; } };
class Serializer2 { public string Name { get; set; } };

interface GenericSerializer<T>
{
      string Name(T tValue);
}

class Serializer<T>: GenericSerializer<T>
{
public string Name(T tValue)
        {
            var prop = tValue.GetType().GetProperty("Name");
            return prop.GetValue(tValue, null) as string;
        }
}

Serializer1 s1 = new Serializer1() { Name = "Serializer1" };
Serializer2 s2 = new Serializer2() { Name = "Serializer2" };

Serializer<Serializer1> serializer1 = new Serializer<Serializer1>();
string name1 = serializer1.Name(s1);

Serializer<Serializer2> serializer2 = new Serializer<Serializer2>();

string name2 = serializer2.Name(s2);






Thursday, April 23, 2015

LINQ Average excluding or including zeros c#

C# > LINQ > Average


Average computes the average of a sequence of numeric values.

Example


int[] int_array = new int[] { 5, 4, 2, 8, 10, 0 };

// linq average excluding zeros

double avg =
       (from ord in int_array
        where ord > 0
        select ord).Average();  // 5.8

// linq average including zeros 
avg =
       (from ord in int_array
       select ord).Average();    // 4.83





Wednesday, April 8, 2015

UPDATE SQL Server Example

SQL Server > DML > UPDATE

Changes existing data in a table or view.


Example


update
   person
set
   name = 'Bill'
where 
   id = 1



Wednesday, April 1, 2015

Reflection to find all classes implementing interface c#

C# > Reflection Find classes implementing interface

var iTtype = typeof(Interface);
var types = AppDomain.CurrentDomain.GetAssemblies()
           .SelectMany(a => a.GetTypes())
           .Where(t => iTtype.IsAssignableFrom(t));





Telerik GridViewCheckBoxColumn Alignment

Telerik > Windows Forms > RadGridView > GridViewCheckBoxColumn

GridViewCheckBoxColumn displays and allows editing of 

boolean data.

Example

GridViewCheckBoxColumn Alignment


<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsManager}" >
    <telerik:GridViewCheckBoxColumn.CellStyle>
        <Style TargetType="telerik:GridViewCell">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
    </telerik:GridViewCheckBoxColumn.CellStyle>


</telerik:GridViewCheckBoxColumn>




Calculate SQL Server row size for a table

SQL Server > Scripts > Row Size


create table ##RowSize (tableName nvarchar(50), rowSize int)
exec sp_msforeachtable 'INSERT INTO ##RowSize Select ''?'' As tableName, SUM(c.Length) from dbo.SysColumns c where c.id = object_id(''?'') '
select * from ##RowSize order by rowSize  desc
drop table ##RowSize