473,657 Members | 3,022 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.RemoveIte m adu

End Sub
Mar 30 '08 #1
10 1131
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.RemoveIte m 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

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

Similar topics

1
2529
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 i176.8005 <CR> i176.800555.44 <CR> o176.8005.222 <CR>
1
1913
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 second line in regards to Me.GetType.... any idea how to get this to work outside of a form? Dim strClass As String = Reflection.Assembly.GetExecutingAssembly.GetName.Name & ".frmChildOne" Dim tyOfStringVariable As Type =...
5
1532
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 and seems to be ok until LOL I add a new person and enter data....when I try to close the form it says this record has been modified by another user and can not be saved...then the save==copy to clipboard===drop changes box comes up. anyone...
9
1558
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 http-equiv="Content-Type" content="text/html; charset=utf-8"> <script language="JavaScript" type="text/JavaScript"> var usernameError = 'Invalid String username';
25
4377
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 opened it in Visual Studio 2005. I've cleared up most errors, but have one that beats the heck out of me. I have a page: sales/Item.aspx that has several datagrids in it.
1
2459
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 that has control or properties that microsoft access does not recognize and will ignore". have tried compacting and repairing and converting to MDE but to no avail. Is there anyone out there who could take a look at it. This is the first database...
1
3069
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 table set. I have successfully set this up and ran some tests using Japanese characters. The test seemed to work fine. We found during our test that we needed to install some AIX UTF-8 software for the web-based user interface to work properly. ...
2
1316
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, to remain hidden (as the user shouldn't be able to access it directly). When the user puts in the length of time into frmMain, I can round it to the nearest 15 minutes just fine for frmPay. Now, when I want to multiply those hours by their hourly...
9
1401
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 bank. I think my formula is right but there are errors i just cant fix. Mostly concerning doubles. Please look at my code and tell me what i did wrong: using System; using System.Collections.Generic; using System.ComponentModel; using...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1601
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.