miercuri, 31 martie 2010

DevExpress: How to select a hole colu...

How to select a hole column in GridView (offered by DevExpress)? 


What I want: on mouse click to select all cells in the column.

public DevExpress.XtraGrid.Views.Grid.GridView m_gridview;
m_gridview.MouseUp += m_gridview_MouseUp;
protected virtual void m_gridview_MouseUp(object sender, MouseEventArgs e)
{
    GridHitInfo _newHitInfo = m_gridview.CalcHitInfo(e.X, e.Y);
    if (e.Button == MouseButtons.Left && _newHitInfo.HitTest == GridHitTest.Column)
    {
            if (!(m_gridview.IsSizingState && m_gridview.State == DevExpress.XtraGrid.Views.Grid.GridState.ColumnSizing))
            {
                   m_gridview.ClearSelection();
                   m_gridview.SelectCells(0, _newHitInfo .Column, m_gridview.RowCount - 1, _newHitInfo.Column);
             }
    }
}

Important to note:
 - use GridHitInfo.HitTest  to know if you are pressing on the column header
 - use GridView.IsSizingState and GridView.State properties to avoid selection when the column is resizing through dragging

Source: DevExpress online documentation.



joi, 25 martie 2010

How to get the string of KeyEventArgs.KeyValue?

I have a method in response to a KeyUp event of a control.

void m_control_KeyUp(object sender, KeyEventArgs e)
{
}

In oder to get the string of the key pressed you have to do something like this:

string _keyPressed = ((char)e.KeyValue).ToString();

But, this is not working all the time. For example if you press "+" you will get in _keyPress a value like ">>".

The solution is to use KeyPress event. This has a KeyPressEventArgs, that has a property KeyChar. Now, the code looks like:

void m_control_KeyPress(object sender, KeyPressEventArgs e)
{
string _keyPressed = e.KeyChar.ToString()
}





joi, 18 martie 2010

User re-sizable text box control that...

User re-sizable text box control that support multiple fonts/colors


What I want to have:
- a user re-sizable text box
- text box in which I can write texts with different colors/fonts

This is how the control looks like and works:



The control that I am created is derived from a UserControl and has two controls inside:
  • a RichTextBox control: this is used for having different fonts/color in the same text box
  • a PictureBox control: used for resizing


Code:

ResizableRichTextBoxCtrl.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace george.lache.Controls
{
/// <summary>
/// - a user re-sizable text box
/// - text box in which it can be written texts with different colors/fonts
/// </summary>
public partial class ResizableRichTextBoxCtrl : UserControl
{
public event EventHandler EditValueChanged;
public new event KeyEventHandler KeyUp;

private readonly List<KeyValuePair<string, Color>> m_texts = new List<KeyValuePair<string, Color>>();
private bool allowResize;

public ResizableRichTextBoxCtrl()
{
InitializeComponent();
}

/// <summary>
/// Gets or sets the current font used for text
/// </summary>
public Font SelectionFont
{
get { return m_richTextBox.SelectionFont; }
set { m_richTextBox.SelectionFont = value; }
}

/// <summary>
/// Gets or sets the Text of control
/// </summary>
public new string Text
{
get { return m_richTextBox.Text; }
set
{
ClearText();
if (string.IsNullOrEmpty(value)) return;

AppendText(value, Color.Black);
m_richTextBox.SelectionLength = 0;
m_richTextBox.SelectionStart = m_richTextBox.Text.Length;
}
}

/// <summary>
/// Gets or sets the starting point of text selected in the text box.
/// </summary>
public int SelectionStart
{
get { return m_richTextBox.SelectionStart; }
set { m_richTextBox.SelectionStart = value; }
}

/// <summary>
/// Apends new text to the existing one.
/// </summary>
/// <param name="i_text">The new text</param>
/// <param name="i_color">The <see cref="Color"/>of the text</param>
public void AppendText(string i_text, Color i_color)
{
if (m_richTextBox.Text.Length == 0)
{
m_richTextBox.Text = " ";
}

m_texts.Add(new KeyValuePair<string, Color>(i_text, i_color));

m_richTextBox.SelectionFont = i_color != Color.Black
? new Font("Tahoma", 8, FontStyle.Bold)
: new Font("Tahoma", 8);

m_richTextBox.SelectionColor = i_color;
m_richTextBox.SelectedText = i_text;

m_richTextBox.SelectionColor = Color.Black;
}


/// <summary>
/// Removes last added text
/// </summary>
public void RemoveLastAddedText()
{
if (m_texts.Count == 0) return;
m_texts.RemoveAt(m_texts.Count - 1);
m_richTextBox.Text = " ";
foreach (var _pair in m_texts)
{
AppendText(_pair.Key, _pair.Value);
}
}

/// <summary>
/// Cleans the text of the control
/// </summary>
public void ClearText()
{
m_richTextBox.Text = string.Empty;
m_texts.Clear();
}

private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
allowResize = true;
}

private void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
allowResize = false;
}

private void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (allowResize)
{
Height = m_pictureBox.Top + e.Y;
Width = m_pictureBox.Left + e.X;
}
}

private void m_richTextBox_TextChanged(object sender, EventArgs e)
{
EventHandler _eh = EditValueChanged;
if (_eh != null)
{
_eh(sender, e);
}
}

private void m_richTextBox_KeyUp(object sender, KeyEventArgs e)
{
KeyEventHandler _eh = KeyUp;
if (_eh != null)
{
_eh(sender, e);
}
}
}
}


ResizableRichTextBoxCtrl.Designer.cs

namespace aptixia.sv.ClientFormula.Controls
{
partial class ResizableRichTextBoxCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ResizableRichTextBoxCtrl));
this.m_pictureBox = new System.Windows.Forms.PictureBox();
this.m_richTextBox = new System.Windows.Forms.RichTextBox();
((System.ComponentModel.ISupportInitialize)(this.m_pictureBox)).BeginInit();
this.SuspendLayout();
//
// m_pictureBox
//
this.m_pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.m_pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
this.m_pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("m_pictureBox.Image")));
this.m_pictureBox.Location = new System.Drawing.Point(128, 11);
this.m_pictureBox.Name = "m_pictureBox";
this.m_pictureBox.Size = new System.Drawing.Size(16, 16);
this.m_pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.m_pictureBox.TabIndex = 8;
this.m_pictureBox.TabStop = false;
this.m_pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseMove);
this.m_pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDown);
this.m_pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseUp);
//
// m_richTextBox
//
this.m_richTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.m_richTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.m_richTextBox.Location = new System.Drawing.Point(-1, -1);
this.m_richTextBox.Name = "m_richTextBox";
this.m_richTextBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.m_richTextBox.Size = new System.Drawing.Size(143, 27);
this.m_richTextBox.TabIndex = 7;
this.m_richTextBox.Text = "";
this.m_richTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.m_richTextBox_KeyUp);
this.m_richTextBox.TextChanged += new System.EventHandler(this.m_richTextBox_TextChanged);
//
// ResizableRichTextBoxCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.m_pictureBox);
this.Controls.Add(this.m_richTextBox);
this.Name = "ResizableRichTextBoxCtrl";
this.Size = new System.Drawing.Size(142, 26);
((System.ComponentModel.ISupportInitialize)(this.m_pictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.PictureBox m_pictureBox;
private System.Windows.Forms.RichTextBox m_richTextBox;

}
}

Use of this control:

resizableRichTextBoxCtrl_1.AppendText("=", Color.Black);
resizableRichTextBoxCtrl_1.AppendText("A1", Color.Blue);
resizableRichTextBoxCtrl_1.AppendText("+", Color.Black);
resizableRichTextBoxCtrl_1.AppendText("b3", Color.Orange);
resizableRichTextBoxCtrl_1.AppendText("+sum", Color.Black);
resizableRichTextBoxCtrl_1.AppendText("h2:i4", Color.Red);



miercuri, 10 martie 2010

Linq to DataSets

Distinct

  • removes duplicate rows from a sequence of object
  • public static IEnumerable<TSource> Distinct<TSource>( this IEnumerable<TSource> source )
  • dataRow.Field<int>(0)
  • IEnumerable<DataRow> distinct = dt.AsEnumerable().Distinct(DataRowComparer.Default)

Except

  • Produces the set of DataRow object difference of two sequences

Intersect

SequenceEqual

  •  compares two sequence of DataRow objects to determine whether they are equal

System.Data.DataRowExtensions

  • Defines the extension methods to the DataRow class. This is a static class.
  • Field<T>
    • where c.Field<int>("ID") == s.Field<int>("ID")
    • Provides strongly-typed access to each of the column values in the DataRow.
    • public static T Field<T>( this DataRow row, string columnName[, DataRowVersion version] )
    • row.AcceptChanges()
      • called to make DataRow object to accept the current value for each DataColumn object within it as the original version
  • SetField<T>
    • Sets a new value for the specified column in the DataRow

DataTable Operators (System.Data.DataTableExtensions)

  •  .AsEnumerable()
    • Returns an IEnumerable<T> object, where the generic parameter T is DataRow. This object can be used in a LINQ expression or method query.
  • .CopyToDataTable<DataRow>
    • Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object.
    • System.Data.LoadOption
      • LoadOption enumeration that specifies the DataTable load options.
        • OverwriteChanges: the incoming values for this row will be written to both the current value and the original value versions of the data for each column.
        • PreserveChanges: the incoming values for this row will be written to the original value version of each column. The current version of the data in each column will not be changed. [This] is the default.
        • Upsert: The incoming values for this row will be written to the current version of each column. The original version of each column's data will not be changed.
        • DataRow.HasVersion
          • to determine if there is an original version
            • dt.AcceptChanges()

System.Data.SqlClient

  • dataSet.Tables["Students"]
  • dataRow.Field<string>("Name")
    • or dataRow.Name in typed DataSet objects
  • studsDS.Students.AddStudentRow(1, "George");
  • studsDS.Students.where(student => student.ID == 7).Single().Name;

  • string connString = @"Data Source = .\SQLEXPRESS; InitialCatalog = Northwing; IntegrationSecurity = SSPI";
    SqlDataAdapter sda = new SqlDataAdapter("Select ... ", connString);
    DataSet ds = new DataSet();
    sda.Fill(ds, "Students");
    ds.Tables("Students").AsEnumerable()
    • Where
    • Distinct



marți, 9 martie 2010

Bianca la un Anisor

Si am facut un an:

- mergem
- ne-am tus ZERO
- mi-a adus tata flori
- si dorm terminata dupa cata jucarii imprastii toata casa




Posted by Picasa

luni, 1 martie 2010

Bianca la Luat din Mot

Si uite asa mi-au luat din mot. In rolurile principale Eu, bineinteles, Mami, Tati, Nana si cu Nanu.
Multe, multe alte poze le gasiti aici.


Posted by Picasa