PDA

View Full Version : return a row



مهدی هادیان2
پنج شنبه 06 بهمن 1390, 16:54 عصر
بسم الله الرحمن الرحیم
با سلام
من در فرم اول فرم دوم رو صدا کردم. در فرم دوم می خوام وقتی روی یه ستون از دیتا گرید کلیک می کنه و دکمه تائید رو می زنه سطر مربوطه به فرم اول برگردانده شود.
کد مربوطه رو در رویداد دکمه تائید به شکل زیر نوشتم

privateDataRow btnOk_Click(object sender, EventArgs e)
{
DataRowView drv = null;
try {
if (dataGridView.CurrentRow == null) { returnnull; }
if (dataGridView.CurrentRow.DataBoundItem == null) { returnnull; }
drv = (DataRowView)dataGridView.CurrentRow.DataBoundItem ;
} catch {
returnnull;
}
return drv.Row;
//DataRow dr = (DataRowView)(dataGridView.CurrentRow.va;
}

ولی خطا می دهد که رویداد کلیک نمی تواند چیزی رو برگرداند

Error 1 'System.Data.DataRow Store.UserInterfaces.SearchCommodity.btnOk_Click(o bject, System.EventArgs)' has the wrong return type
کد مربوط به سطر انتخاب شده در دیتا گرید صحیح است؟

privateDataRow btnOk_Click(object sender, EventArgs e)
{
DataRowView drv = null;
try {
if (dataGridView.CurrentRow == null) { returnnull; }
if (dataGridView.CurrentRow.DataBoundItem == null) { returnnull; }
drv = (DataRowView)dataGridView.CurrentRow.DataBoundItem ;
} catch {
returnnull;
}
return drv.Row;
//DataRow dr = (DataRowView)(dataGridView.CurrentRow.va;
}

فرید نجفلو
شنبه 15 بهمن 1390, 01:56 صبح
خسته نباشید
از ظواهر قضیه شما از متد ShowDialog فرم استفاده کردید(درسته؟)
که در این صورت مقدار برگشتی باید از نوع System.Windows.Forms.DialogResult باشه که اینطور نیست.
شما باید یک متد جدید بسازید و اونو از فرم اول صدا بزید یا همون ShowDialog رو Overload کنید.
در ضمن خط زیر در متد جدید یادتون نره
this.ShowDialog