PDA

View Full Version : ایونت TextBox_Change در دیتاگرید ویو



parsamiga
یک شنبه 18 اسفند 1387, 12:54 عصر
سلام
من میخوام زمانی که در یک سلول دیتاگرید ویو حرفی رو وارد میکنم بتونم تابعی رو فراخوانی کنم .نکته این جاست فقط زمانی که یک سلول در " حال " تغییره میخوام این کار رو بکنم . در واقع از ایونتهای CellBeginEdit و CellEndEdit و CellValueChanged نمی خوام استفاده کنم .
یه چیزی شبیه ایونت TextBox_Change یک تکست باکس؟؟

کسی اگه بلده راهنمایی کنه.لطفا چیزی رو که تست کردین و درست بوده بگین چون من تقریبا همه راهها رو تست کردم ولی نتیجه نگرفتم.

h.jaza
یک شنبه 18 اسفند 1387, 15:36 عصر
همون رویداد هایی که گفتی، در واقع جای یه دونه رویداد TextChanged در تکست باکس هستش و متناسب با کارت، با هر کدوم میشه کار کرد.

اگر کاره خاصی رو می خوای که با اینها نمیشه یا نمی تونی، اون رو مطرح کن...

parsamiga
چهارشنبه 21 اسفند 1387, 10:16 صبح
من میخوام زمانی که شما حرفی رو وارد میکنید یه تابع اجرا بشه ، در این ایونت ها حتما باید عمل ادیت سلول به پایان برسه یا اینکه تا انتخاب میشه تابعی رو میشه اجرا کرد و من هیچکدوم از اینا رو نمیخوام ، می خوام فقط زمانی اتفاق بیفته که کاربر حرفی رو تایپ میکنه دقیقا مثل ایونت TextBox_Change ...

araz_pashazadeh
چهارشنبه 15 آذر 1391, 18:19 عصر
دوست عزیز شما می تونین بصورت زیر این کار را انجام بدین دقیقا مثل تکس باکس:

private void dataGridViewProduct_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
TextCell = e.Control as TextBox;


if (dataGridViewProduct.CurrentCell.ColumnIndex == 3)
{
if (TextCell != null)
{
if (!string.IsNullOrEmpty(TextCell.Text))
dataGridViewProduct.EditingControl.Text = dataGridViewProduct.CurrentRow.Cells["PriceBuyG"].EditedFormattedValue.ToString().Remove(0, 5);
TextCell.TextChanged += new EventHandler(txtCash_TextChanged);
}
}
e.CellStyle.BackColor = Color.Pink;
}
catch (Exception ex)
{
MessageBox.Show("..........................خـطـا در درج اطـلاعـات........................... \n" + " \n" + ex.Message, "خـطـا",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}


private void txtCash_TextChanged(object sender, EventArgs e)
{
DataGridViewTextBoxEditingControl editControl = new DataGridViewTextBoxEditingControl();
try
{
if (dataGridViewProduct.CurrentRow.Cells["PriceBuyG"].EditedFormattedValue.ToString() != String.Empty &&
dataGridViewProduct.IsCurrentCellDirty)
{
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalDigits = 0;
editControl = (DataGridViewTextBoxEditingControl)dataGridViewPro duct.EditingControl;
editControl.SelectionStart = editControl.Text.Length;
editControl.SelectionLength = 1;
dataGridViewProduct.EditingControl.Text = Decimal.Parse(dataGridViewProduct.CurrentRow.Cells["PriceBuyG"].EditedFormattedValue.ToString(),
NumberStyles.AllowThousands).ToString("N", nfi);
}
}
catch (FormatException)
{
dataGridViewProduct.CurrentRow.ErrorText = "مبلغ را صحیح وارد نمایید";
if (notifyIconForCheck != null)
notifyIconForCheck.Dispose();
notifyIconForCheck = new System.Windows.Forms.NotifyIcon();
//notifyIconForCheck.BalloonTipIcon = ToolTipIcon.Info;
notifyIconForCheck.Icon = SystemIcons.Information;
notifyIconForCheck.Text = "مبلغ را صحیح وارد نمایید";
notifyIconForCheck.Visible = true;
notifyIconForCheck.ShowBalloonTip(4000, "مبلغ را صحیح وارد نمایید", dataGridViewProduct.EditingControl.Text, ToolTipIcon.Info);
dataGridViewProduct.EditingControl.Text = dataGridViewProduct.CurrentRow.Cells["PriceBuyG"].EditedFormattedValue.ToString().Remove(
dataGridViewProduct.CurrentRow.Cells["PriceBuyG"].EditedFormattedValue.ToString().Length - 1, 1);
this.notifyIconForCheck.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notify IconForCheck_MouseClick);
}


در تکه کد بالا هنگام ورود اطلاعات نامعتبر پاک شده و بالن نمایش داده می شود.