473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

troubles converting code form VB to C#

8 New Member
i need to convert this code into C #.. i am having the same problem with my code as did this person.. i need to replace a item in a listbox with text from a text box using a button..

THis is the VB code:
Dim adu As Integer
Private Sub Command1_Click()
List1.AddItem Text1, adu
End Sub

Private Sub Form_Load()
List1.AddItem "Ravi"
List1.AddItem "Dinesh"
List1.AddItem "Sushmita"
List1.AddItem "Mrunalini"

End Sub

Private Sub List1_Click()

adu = List1.ListIndex
List1.RemoveItem adu

End Sub
Mar 30 '08 #1
10 1122
weaknessforcats
9,208 Recognized Expert Moderator Expert
Moving this to the .NET forum.
Mar 30 '08 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
You may have to recreate the form again as the code behind / the designer code is still generated in VB.

Once you have done designing the form (will be exactly the same as you did with a vb project) look into the events in the properties window for the form and the listbox. Double click on the load event for the form, and the click event of the list box.

In the cs file then code for populating and the click event

The syntax is almost the same and with intellisense it shouldnt be a problem.
Mar 30 '08 #3
Zubulake
8 New Member
i got this code from some post online.. i dont have the rest of the program..
Mar 31 '08 #4
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
If you do realise Command1_click, form_load and List1_Click are event handlers which occour when they are clicked, loaded, clicked

Hope the website also has a snapshot of the form to which this code refers to.

Create the form, and then register the event handlers.

i need to convert this code into C #.. i am having the same problem with my code as did this person.. i need to replace a item in a listbox with text from a text box using a button..

THis is the VB code:
Dim adu As Integer
Private Sub Command1_Click()
List1.AddItem Text1, adu
End Sub

Private Sub Form_Load()
List1.AddItem "Ravi"
List1.AddItem "Dinesh"
List1.AddItem "Sushmita"
List1.AddItem "Mrunalini"

End Sub

Private Sub List1_Click()

adu = List1.ListIndex
List1.RemoveItem adu

End Sub
Mar 31 '08 #5
Zubulake
8 New Member
can you help make a code that i need. i am very frustrated with this.

I have a listbox, button, and textbox..

i need to be able to replace something in the listbox with the text in the textbox using the button..
Mar 31 '08 #6
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. private int adu;
  2.  
  3.         private void lstBx_Load(object sender, EventArgs e)
  4.         {
  5.             this.List1.Items.Add("a1");
  6.             this.List1.Items.Add("a2");
  7.             this.List1.Items.Add("a3");
  8.             this.List1.Items.Add("a4");
  9.         }
  10.  
  11.         private void Command1_Click(object sender, EventArgs e)
  12.         {
  13.             if (this.Text1.Text.Length <= 0)
  14.                 return;
  15.             this.List1.Items.Add(this.Text1.Text);
  16.         }
  17.  
  18.         private void List1_Click(object sender, EventArgs e)
  19.         {
  20.             adu = this.List1.SelectedIndex;
  21.             if (adu < 0)
  22.                 return;
  23.             this.List1.Items.RemoveAt(adu);
  24.         }
Mar 31 '08 #7
Zubulake
8 New Member
thanks.. appreciate it.. What does "this." mean.. not that far in the class yet
Mar 31 '08 #8
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
this is the equivalent of Me from vb .Net

this.List1 would explicitly define to use the List1 which belongs to the object.

this thus referring to the current object from where it is being called.

It will still work without using the this keyword
Mar 31 '08 #9
Zubulake
8 New Member
ok, thanks for the help but it doesn do what i want.. i dont want it to remove it when i double click, but remove when i hit the button.. is it possible to put the new item in the same place as the one that got removed
Apr 1 '08 #10
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
ok, thanks for the help but it doesn do what i want.. i dont want it to remove it when i double click, but remove when i hit the button.. is it possible to put the new item in the same place as the one that got removed
But isint th button adding whats in the text box ?
Secondly, with a single click the item is being removed. (not double click)
To add a text at a specific item replace the add with
this.List1.Items.Insert(adu, this.Text1.Text);

you will have to store the new value of adu when u click in the listbox

cheers
Apr 1 '08 #11

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

Similar topics

1
2518
by: Pete | last post by:
Hello, Have just started using VB.Net and have been trying to work on some updates to a very old piece of code. Currently we send messages via the serial port in the following formate ...
1
1907
by: Kevin S Gallagher | last post by:
I found this code (pretty sure it was from a MVP) for converting a string variable to a form object which works fine within a form. Take the code and place it into a code module and it fails on the...
5
1524
by: sparks | last post by:
We are slowly converting all of our older access 97 databases to 2003. One of them that has been running fine for 3 + years and has over 2000 records in is giving me a problem. It converted fine...
9
1544
by: whisher | last post by:
Hi. I've managed this simple snippet: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Register</title> <meta...
25
4349
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have...
1
2443
by: murraystewart | last post by:
I have spent days building a database in access 2003 and the found it needs to run on Access 97, I did the conversion but the form is not opening with an error message "you loaded a form or report...
1
3062
by: shorti | last post by:
Hello, I am running DB2 UDB 8.2 on AIX 5.3. I am running some tests on converting several tables on an existing database to Unicode. The database will not be converted to unicode...just this...
2
1310
by: isoquin | last post by:
I have frmMain that takes in data about a particular event. Payroll information needs to be automatically calculated from this, but is stored in a different table. So, I included a subform frmPay,...
9
1390
by: Jeffro | last post by:
Ok I have some troubles with my code. I don't need a full solution. I just want to know what i should do best for this situation. The idea is to calculate the amount of money that will be on the...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.