PDA

View Full Version : میخوام شماره ردیو باتن رو توی حلقه بدم



sm_ezadpanah
شنبه 30 تیر 1386, 16:25 عصر
با سلام من می خوام text تعدادی radio button و label رو داخل یک حلقه به صورت زیر بدم :
for (i=1;i<=10;i++)
radiobuttonشماره i.text=یه چیزی
یعنی میخوام توی حلقه شماره ردیو باتن را مشخص کنم .که در اصل همون شمارنده حلقه است .

ghafoori
شنبه 30 تیر 1386, 17:06 عصر
دوست عزیز می توانی از این کد استفاده بکنی


int i;
RadioButton r;
string s;
for (i = 1; i <= 10; i++) {
r = (RadioButton )this.Controls["radiobutton" + i.ToString()];
s = r.Text;
}

sm_ezadpanah
یک شنبه 31 تیر 1386, 13:56 عصر
ممنون از راهنماییتون
موقع اجرا از s=r.text ارور میگیره

ghafoori
یک شنبه 31 تیر 1386, 14:31 عصر
خطا را اینجا بزن ببینم مشکل از کجا است قاعدتا نباید خطا بدهد

sm_ezadpanah
دوشنبه 01 مرداد 1386, 15:41 عصر
کدی رو که شما گذاشتی من دقیقا بدون هیچ تغییری کپی کردم که error زیر رو داد .
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="amozesh"
StackTrace:
at amozesh.azmon.azmon_Load(Object sender, EventArgs e) in E:\ایزدپناه\c#\amozesh\amozesh\azmon.cs:li ne 54
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessa ge(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at amozesh.sub.button1_Click(Object sender, EventArgs e) in E:\ایزدپناه\c#\amozesh\amozesh\sub.cs:line 33
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at amozesh.Form1.آزمونسراسری80ToolStripMen uItem_Click(Object sender, EventArgs e) in E:\ایزدپناه\c#\amozesh\amozesh\Form1.cs:li ne 52
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(Eve ntArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(M ouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Mes sage& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at amozesh.Program.Main() in E:\ایزدپناه\c#\amozesh\amozesh\Program.cs: line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

sm_ezadpanah
دوشنبه 01 مرداد 1386, 15:42 عصر
آخ ببخشید هم رو کپی کردم

sm_ezadpanah
دوشنبه 01 مرداد 1386, 15:56 عصر
آخ ببخشید هم رو کپی کردم

ghafoori
دوشنبه 01 مرداد 1386, 17:11 عصر
دوست عزیز بیشتر مشکل از حلقه است یک radiobutton وجود ندارد و شما ان را فراحوانی می کنید
داخل این خط نیز اگر کنترل وجود نداشته باشد خطا نمی گیرد
r = (RadioButton )this.Controls["radiobutton" + i.ToString()
ولی برای خط بعدی دچار مشکا می شود

sm_ezadpanah
سه شنبه 02 مرداد 1386, 12:02 عصر
ولی من حدود 60 تا ردیو دارم که اسمشون به ترتیب ردیو 1 تا 60 و میخوام داخل حلقه به خاصیت text شون متن مورد نظر بدم .و مطمئن هستم که ردیو 1 تا 60 وجود داره

sm_ezadpanah
سه شنبه 02 مرداد 1386, 12:13 عصر
بازم چک کردم ولی نشد

sm_ezadpanah
پنج شنبه 04 مرداد 1386, 10:15 صبح
چی شد هیشکی چیزی نداشت

ghafoori
پنج شنبه 04 مرداد 1386, 17:32 عصر
د وست عزیز وقتی برنامه خطا می دهد مقدار i برابر چند است

sm_ezadpanah
یک شنبه 07 مرداد 1386, 15:32 عصر
ضمنا من می خوام چند تا ازradiobutton ها ی رو فرم را تو حلقه بدم