Saturday 8 June 2013

filter max and min value from table on code behind

string pp=DataTable.Compute("Max(ColumnsName)",string.empty).ToString();

and From dataview---------------

Dataview.RowFilter = "Max(ColumnsName)";

Friday 7 June 2013

select cursor position in textbox control


TextBox1.Select(Start Length,End Length);
//------------------
TextBox1.Select(TextBox1.Text.Length,Length);

Wednesday 5 June 2013

windows-rotate lable 90 degree with paint

 private void label123_Paint(object sender, PaintEventArgs e)
        {
StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;

            SizeF txt = e.Graphics.MeasureString("Loans", this.Font);
            SizeF sz = e.Graphics.VisibleClipBounds.Size;
            //270 degrees

            e.Graphics.TranslateTransform(0, sz.Height);
            e.Graphics.RotateTransform(270);
            e.Graphics.DrawString("Loans", this.Font, Brushes.Black, new RectangleF(0, 0, sz.Height, sz.Width), format);
            e.Graphics.ResetTransform();
}

windows- create multiple header in datagridview using paint

private void DVG_familyInfo_Paint(object sender, PaintEventArgs e)
        {
            for (int j = 0; j < DVG_familyInfo.ColumnCount; j++)
            {
                if (j == 5 || j == 9 || j == 11)
                {

                    if (j == 5)
                    {
                        Rectangle r1 = this.DVG_familyInfo.GetCellDisplayRectangle(j, -1, true);
                        int w2 = this.DVG_familyInfo.GetCellDisplayRectangle(j + 1, -1, true).Width;
                        r1.Width = (r1.Width * 3) - 2;
                        r1.Height = (r1.Height / 2) - 1;
                        e.Graphics.FillRectangle(new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.BackColor), r1);
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;
                        format.LineAlignment = StringAlignment.Near;
                        e.Graphics.DrawString("Date of Birth",
                        this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.Font,
                        new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.ForeColor), r1, format);
                        DVG_familyInfo.Columns[j].Width = 55;
                    }
                    if (j == 9)
                    {
                        Rectangle r1 = this.DVG_familyInfo.GetCellDisplayRectangle(j, -1, true);
                        int w2 = this.DVG_familyInfo.GetCellDisplayRectangle(j + 1, -1, true).Width;
                        r1.X += 1;
                        r1.Y += 1;
                        r1.Width = r1.Width + w2 - 2;
                        r1.Height = r1.Height / 2 - 2;
                        e.Graphics.FillRectangle(new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.BackColor), r1);
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;
                        format.LineAlignment = StringAlignment.Near;

                        e.Graphics.DrawString("Education Qualification",
                        this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.Font,
                        new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.ForeColor), r1, format);
                    }
                    if (j == 11)
                    {
                        Rectangle r2 = this.DVG_familyInfo.GetCellDisplayRectangle(j, -1, true);
                        int w2 = this.DVG_familyInfo.GetCellDisplayRectangle(j + 1, -1, true).Width;
                        r2.X += 1;
                        r2.Y += 1;
                        r2.Width = r2.Width + w2 - 2;
                        r2.Height = r2.Height / 2 - 2;
                        e.Graphics.FillRectangle(new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.BackColor), r2);
                        StringFormat format2 = new StringFormat();
                        format2.Alignment = StringAlignment.Center;
                        format2.LineAlignment = StringAlignment.Near;
                        e.Graphics.DrawString("Occupation",
                        this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.Font,
                        new SolidBrush(this.DVG_familyInfo.ColumnHeadersDefaultCellStyle.ForeColor), r2, format2);
                    }
                }
            }
        }
        private void DVG_familyInfo_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            Rectangle rtHeader = this.DVG_familyInfo.DisplayRectangle;
            rtHeader.Height = this.DVG_familyInfo.ColumnHeadersHeight / 2;
            this.DVG_familyInfo.Invalidate(rtHeader);
        }
        private void DVG_familyInfo_Scroll(object sender, ScrollEventArgs e)
        {
            Rectangle rtHeader = this.DVG_familyInfo.DisplayRectangle;
            rtHeader.Height = this.DVG_familyInfo.ColumnHeadersHeight / 2;
            this.DVG_familyInfo.Invalidate(rtHeader);
        }

windows- gridview specific header cell font and cell font

this.dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font(this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);
For Single Header Column
this.dataGridView1.Columns[0].HeaderCell.Style.Font = new Font(this.Font, FontStyle.Bold);
For Column
this.dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(this.Font, FontStyle.Bold);

windows- Change back color of a specific column header in datagridview c#.net

DVG_familyInfo.Rows[0].Cells["VFAMember"].OwningColumn.HeaderCell.Style.BackColor = validateColor;
               DVG_familyInfo.EnableHeadersVisualStyles = false;

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...