473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Windows Forms Fatch Combobox's value Problem

KalariaNitya
hello all,

i need ur help..

i have 10 combobox & 10 textbox on windows forms

it's names like :

cmbsign1 txtdiscount1
cmbsign2 txtdiscount2
cmbsign3 txtdiscount3
cmbsign4 txtdiscount4
cmbsign5 txtdiscount5


i just make a for loop to fatch combobox and textbox's value
Expand|Select|Wrap|Line Numbers
  1. dim sign as new combobox
  2. dim discount as new textbox
  3.  
  4.    j=1
  5.    For i = 0 To 10
  6.                 sign = CType("cmbSign" & j, ComboBox)
  7.  
  8.                 txt.Name = "discount" & j
  9.                 discount.Text = txt.Text
  10.  
  11.                 MsgBox(discount.Text)
  12.  
  13.                 discount.Text = ("txtdiscount" & j)
  14.                 commission.Text = ("txtcommission" & j)
  15.  
  16.                 j = j + 1
  17.    Next
  18.  
i.e.
================
sign = CType(cmbSign1, ComboBox) if we do like this then work but i want

sign like
sign = CType("cmbSign" & j, ComboBox)

it gives error that can not convert from string to combobox..

can anybody help me?

any help will be appriciated..

thanking u in advanced..
Jun 3 '08 #1
6 1252
shweta123
692 Expert 512MB
Hi ,

You can try this code for your requirement :

Expand|Select|Wrap|Line Numbers
  1. //variables for program
  2. string txtName="";
  3. string cmbName="";
  4. string txtValue;
  5. string cmbValue;
  6. TextBox t1 = new TextBox();
  7. ComboBox c1 = new ComboBox();
  8.  
  9. //For loop to get Textbox and Combo box values on the Form
  10. for (int i = 1; i <= 10; i++)
  11. {
  12.  
  13. //define textbox name 
  14. txtName = "txtdiscount" + i;
  15.  
  16. //define combobox name
  17. cmbName = "cmbSign" + i;
  18.  
  19. //Get textbox control
  20. t1 = (TextBox)this.Controls[txtName];
  21.  
  22. //Get combobox control
  23. c1 = (ComboBox)this.Controls[cmbName];
  24.  
  25. //Get combo box value
  26. cmbValue = c1.Text;
  27.  
  28. //Get textbox value
  29. txtValue = t1.Text;
  30.  
  31. }
  32.  
Jun 3 '08 #2
hi, shweta

first of all thanks..

u send me code in c# right?

i have to convert it into vb.net
Expand|Select|Wrap|Line Numbers
  1.  Dim discounttxt As New TextBox 
  2. For i = 0 To 2
  3.  
  4. Dim b As String
  5. Dim c As String
  6. b = "txtdiscount" & j
  7.  
i got the value of b
Expand|Select|Wrap|Line Numbers
  1.  discounttxt = CType(Me.Controls(b), TextBox) 
  2. c = discounttxt.Text
  3.  
  4. Next
  5.  
but can't get discounttxt.
i got value Nothing
i didn't get textbox control

do u have any idea?

thanking u in advanced..............
Jun 3 '08 #3
shweta123
692 Expert 512MB
Hi,

For getting the value of discounttxt you have to add following code in your existing vb .net code :

Expand|Select|Wrap|Line Numbers
  1.  Dim discounttxt as new TextBox 
  2.  
  3. For i = 0 To 2
  4. Dim b As String
  5. Dim c As String
  6. b = "txtdiscount" & j
  7.  
  8. '''''''Get textbox control here 
  9. discounttxt = CType(me.Controls(b),"TextBox")
  10.  
  11. '''''''''''Get the value of discount textbox
  12. c = discounttxt.Text
  13. Next
  14.  
Jun 3 '08 #4
hi shweta
first of thanks, for replying me such fast...

thanks i had done according to u. but still i didn't get textbox as NOTHING

i just try following code..
i know it bit longer then u suggested..but will work now..code as follows:
Expand|Select|Wrap|Line Numbers
  1.  
  2. For ksign = 1 To 10
  3. strsign = "cmbsign" & ksign
  4. sign = Me.Controls("pnlCategoryInfo").Controls(strsign)
  5. signvalue = sign.Text
  6. Next
  7.  
  8. 'for discount 
  9. For kdiscount = 1 To 10
  10. strdisount = "txtdiscount" & kdiscount
  11. discount = Me.Controls("pnlCategoryInfo").Controls(strdisount)
  12. Next
  13.  
  14. 'for commission 
  15. For kcommission = 1 To 10
  16. strcommission = "txtcommission" & kcommission
  17. commission = Me.Controls("pnlCategoryInfo").Controls(strcommission)
  18. Next
  19.  
once again thanks,
Jun 4 '08 #5
shweta123
692 Expert 512MB
Hi,

Where are you getting error in this code?
Jun 4 '08 #6
Hello,
above pasted code is perfactly working..

i had done it..

thanks 4 ur help..

i told u that b4 one was not working..

any ways, have a great day ahead..
thanks again



Hi,

Where are you getting error in this code?
Jun 4 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cro | last post by:
Dear Access Developers, I am developing a form with 'default view' set to "continuous forms". I am suffering with a problem I can't yet see a solution too. Each record has many fields. Two...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
0
by: Martin Henke | last post by:
Dear all, I've got a problem with my custom combo box. When I select an entry from it, then I get the error message: "An unhandled exception of type 'System.ArgumentOutOfRangeException'...
0
by: Jake Montgomery | last post by:
I am using .NET 2.0 forms and running on Windows XP SP2. When I have a tooltip on a combo box, and the combo box is expanded (“dropped down”) using the arrow, it will no longer display it’s...
6
by: Nathan Laff | last post by:
Why when I inherit a ComboBox and make no code changes, when I set the new control DropDownStyle to dropDownList it appears different than the standard ComboBox control on Vista? In Windows...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
3
by: nityaprashant | last post by:
hello.. i have grid view.. in that template column i want to fatch product name form selected row.. i had done code like below.. but it fatch all row's product name one by one.. i want...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.