PDA

View Full Version : ساخت کامپوننت DataGridView ویژه



davidrobert
یک شنبه 07 تیر 1394, 13:57 عصر
ساخت کامپوننت دیتاگرید ویو با خواصیت highlight کردن اطلاعات یکی در میان با خواصیت enter به دو روش سطر جدید و پایین و همین طور وقتی سلولی رو انخاب میکنید برای تغییر رنگ آن سلول عوض میشه.
این سورس مورد نظر.که با class ساخته شده است.
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Objects;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using DevComponents.DotNetBar.Controls;

namespace Accounting_Program_Canopy_Store_Full.Components
{
public class DGV : DataGridViewX
{
//private Stimulsoft.Report.Viewer.StiViewerControl stiViewerControl1; //private bool enterIsTab = true;

/// <summary>
/// طرح از یونس مرباغی اسکوئی مورخه94/3/7
/// </summary>
//[Category("Behavior"), Description("Disable default edit/advance to next row behavior of of the Enter key.")]
public bool GONextCell { get; set; }

/// <summary>
/// تعریف رویداد اینتر به جای تب
/// </summary>
///
///
///
///
//protected override bool ProcessDialogKey(Keys keyData)
//{
// if (keyData == Keys.Enter)
// {
// base.ProcessTabKey(Keys.Tab);
// return true;
// }
// return base.ProcessDialogKey(keyData);
//}
//protected override bool ProcessDataGridViewKey(KeyEventArgs e)
//{
// if (e.KeyCode == Keys.Enter)
// {
// base.ProcessTabKey(Keys.Tab);
// return true;
// }
// return base.ProcessDataGridViewKey(e);
//}
//protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
//{

// if (GONextCell && keyData == Keys.Enter)
// {

// if (this.CurrentCell.ColumnIndex < ColumnCount - 1)
// {
// this.CurrentCell = this.Rows[this.CurrentCell.RowIndex].Cells[this.CurrentCell.ColumnIndex + 1];
// return true;
// }
// else
// {
// try
// {
// this.CurrentCell = this.Rows[this.CurrentCell.RowIndex + 1].Cells[0];
// return true;
// }
// catch (ArgumentOutOfRangeException ex)
// {
// ApplicationException exTop = new ApplicationException("", ex);
// return true;
// }

// }
// }
// return base.ProcessCmdKey(ref msg, keyData);
//}

protected override bool ProcessDialogKey(Keys keyData)
{
if (GONextCell && keyData == Keys.Enter)
{
base.ProcessTabKey(Keys.Tab);
return true;
}
return base.ProcessDialogKey(keyData);
}

protected override bool ProcessDataGridViewKey(KeyEventArgs e)
{
if (GONextCell && e.KeyCode == Keys.Enter)
{
base.ProcessTabKey(Keys.Tab);
return true;
}
return base.ProcessDataGridViewKey(e);
}





private Color _Alternating = Color.Yellow;

public Color AlteraningColor
{
get
{
return _Alternating;
}
set
{
_Alternating = value;
DataGridViewCellStyle objCellStyle = new DataGridViewCellStyle();
objCellStyle.BackColor = this._Alternating;
this.AlternatingRowsDefaultCellStyle = objCellStyle;
}
}

//protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
//{
// if (msg.WParam.ToInt32() == (int)Keys.Enter)
// {
// if (enterIsTab)
// {
// SendKeys.Send("{tab]");

// return true;

// }
//
// return base.ProcessCmdKey(ref msg, keyData);
//}

protected override void OnEditingControlShowing(DataGridViewEditingControl ShowingEventArgs e)
{
base.OnEditingControlShowing(e);
e.CellStyle.BackColor = Color.Pink;
}

private void InitializeComponent()
{
//this.stiViewerControl1 = new Stimulsoft.Report.Viewer.StiViewerControl();
((System.ComponentModel.ISupportInitialize) (this)).BeginInit();
this.SuspendLayout();
//
// stiViewerControl1
//
//this.stiViewerControl1.AllowDrop = true;
//this.stiViewerControl1.IgnoreApplyStyle = false;
//this.stiViewerControl1.Location = new System.Drawing.Point(0, 0);
//this.stiViewerControl1.Name = "stiViewerControl1";
//this.stiViewerControl1.Report = null;
//this.stiViewerControl1.ShowZoom = true;
//this.stiViewerControl1.Size = new System.Drawing.Size(721, 443);
//this.stiViewerControl1.TabIndex = 0;
((System.ComponentModel.ISupportInitialize) (this)).EndInit();
this.ResumeLayout(false);

}



public int Selected_Row = -1, Selected_Column = -1;



//protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
//{
// const int WM_KEYDOWN = 0x100;
// const int WM_SYSKEYDOWN = 0x104;
// if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
// {
// switch (keyData)
// {
// case Keys.Enter:
// try
// {
// grid1.CurrentCell = grid1[grid1.CurrentCell.ColumnIndex + 1, grid1.CurrentCell.RowIndex];
// }
// catch { }
// return true;
// case Keys.Right:
// try
// {
// grid1.CurrentCell = grid1[grid1.CurrentCell.ColumnIndex - 1, grid1.CurrentCell.RowIndex];
// }
// catch { }
// return true;
// case Keys.Left:
// try
// {
// grid1.CurrentCell = grid1[grid1.CurrentCell.ColumnIndex + 1, grid1.CurrentCell.RowIndex];
// }
// catch { }
// return true;
// case Keys.Up:
// try
// {
// grid1.CurrentCell = grid1[grid1.CurrentCell.ColumnIndex, grid1.CurrentCell.RowIndex - 1];
// }
// catch { }
// return true;
// case Keys.Down:
// try
// {
// grid1.CurrentCell = grid1[grid1.CurrentCell.ColumnIndex, grid1.CurrentCell.RowIndex + 1];
// }
// catch { }
// return true;
// }
// }
// return base.ProcessCmdKey(ref msg, keyData);
//}



}
}


لایم یا تشکر فراموش نشود و دوستانی که تخصص در ساخت کامپوننت و کلاس نویسی دارن در این تاپیک فقط کلاس نویسی و کامپوننت با سورس رو قرار بدن تا دوستان دیگر استفاده کنن تا باعث پیشرفت در کد نویسی شود.
با تشکر