|
This is the right approach. With combos, listboxes, ,etc etc etc...you can add an object. It doesn't matter what the object is. You can add properties out the whazzoo for whatever you want and just use a display member like riced suggested above.
Create a custom KeyValuePair class to suit your needs.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for your efforts and time. I tried with your code and it is working fine, Combo box is displaying only the FirstString. However to retrieve records from combobox I have writen this code
Private Sub CboProject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboProject.SelectedIndexChanged
GetProjectID(Me.CboProject.SelectedIndex)
End Sub
Public Sub GetProjectID(ByVal iIndex As Int32)
Dim d1 As TheData = New TheData
d1 = Me.CboProject.Items.Item(iIndex)
RichTextBox1.Text = d1.SecondString.ToString()
RichTextBox1.Text = RichTextBox1.Text & " " & d1.FirstString.ToString()
End Sub
Problem Description : Irrespective of the iIndex value FirstString and SecondString always are returnig the last record.
|
|
|
|
|
Not sure why that is happening.
I used the following to test it. The only difference is that I'm getting a new object each time.
You might also look at my versions of the other to subs - they don't need the index and I make an explicit cast to type TheData.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim d As TheData = New TheData()
Me.cboProject.BeginUpdate()
d.firstString = "Duke"
d.secondString = "USA"
Me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
d = New TheData()
d.firstString = "Alice"
d.secondString = "England"
Me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
d = New TheData()
d.firstString = "Bob"
d.secondString = "Australia"
Me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
d = New TheData()
d.firstString = "Duncan"
d.secondString = "Scotland"
Me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
d = New TheData()
d.firstString = "Puneet"
d.secondString = "India"
Me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
Me.cboProject.EndUpdate()
End Sub
Private Sub CboProject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProject.SelectedIndexChanged
GetProjectID()
End Sub
Public Sub GetProjectID()
Dim d1 As TheData = New TheData()
d1 = CType(Me.cboProject.SelectedItem, TheData)
RichTextBox1.Text = d1.secondString
RichTextBox1.Text = RichTextBox1.Text & " " & d1.firstString
End Sub Hope this helps.
|
|
|
|
|
I put my thinking head on and came up with the following reason for this seemingly odd behaviour.
Comboboxes (and Listboxes) maintain two collections. One is the Items collection, the other a collection of strings that will be displayed by the list box part of the control.
When you insert (or add) an object two things happen. First a reference to the object is placed in the Items collection. Secondly, the object's ToString() method is called and the result placed in the hidden strings collection. This is what is displayed in the list.
With the code I used the d = New TheData() creates five objects on the heap and references to these objects are placed in Items collection.
When the d = New TheData() lines are commented out, only one object is created on the heap (when d is Dimmed). So all of the references in Items collection point to the same object. This object will have the values last inserted into the list. The selection methods of the combobox operate on the Items collection so they will return what appears to be the last item inserted for all positions.
Because of the two collections, the displayed list can be quite different to what is actually in the Items collection. In the SelectedItemsChanged handler you could update the fields in the item, e.g. by setting secondString to "Impossible", but this would not change the displayed list.
As far as I'm aware you cannot get direct access to the strings collection. The Combobox control maintains this collection when you add, insert or remove items.
Note that the Listbox control behaves in exactly the same way.
Regards
David Rice
|
|
|
|
|
Hi,
just like a ListBox, a ComboBox can be made to contain objects, not just strings; when using the
OwnerDrawn DrawMode you can make it show one string, while its items actually are objects of your design, holding anything you want, e.g. two strings.
|
|
|
|
|
How can we can get the Network systems in a list through vb program
looking for positive response
Jay
|
|
|
|
|
jayacc wrote: subject: visual basic
A question about visual basic ? Here, in the Visual Basic forum ? Wow...
Read the guide on how to ask questions. The subject is very important, it attracts people who can help you.
I *think* you want a list of visible networks, is that right ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
Your question subject is horrible and your actual question is equally as bad.
My mind telepathy is turned off today, so please clearly state what you are trying to accomplish so that others may attempt to help you and not "spin their wheels" guessing.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
can any one help me how to save only editable data/row from MSFlexgrid to database in vb 6.0
modified on Tuesday, December 9, 2008 3:59 AM
|
|
|
|
|
Why are you using VB6 ? Can't you get out of it ? That language is dead and buried. At a minimum, put VB6 in your subject so the three people still alive and using VB6 can see your question and try to answer it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Is there anyone who can kindly provide me with example of computers via tcp/ip. I am writing an application that run on 2 different computer and i have to get the 2 application from the computer to work together.. What can i do to achieve this assume this 2 computers are in the same network?
urgent help needed.. thanks..
|
|
|
|
|
Look into Remoting[^]
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Isn't remoting means controlling remotely? Does communication between computers share the same topic?
|
|
|
|
|
Remoting is away of communicating between different computers. You could also look into the Microsoft Message Queue (MSMQ) and Web Services.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I don't intend to do a web application. Is window application ok for communicating between computers?
|
|
|
|
|
Hi everyone,
can please help me, i am going to implement the vedio to play,in my application using vb.net.
i have no idea how to work out it.anyone give me code to this.
thanks in advance.
JohnDas
|
|
|
|
|
Seriously ? You typed 'play video VB.NET' into google and couldn't find one reference ?
Drag the windows media player control onto your form ( you may need to add it to the available options, which you do via the right click menu ), point it to your video and you're done.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi,
I'm having a problem when creating an ms access database using the following code:
Imports System.Data.OleDb
Public Class Database
Public Function CreateDatabase(ByVal FileName As String) As Boolean
Dim ADOXCatalog As ADOX.Catalog = New ADOX.Catalog
Dim ADOXTable As ADOX.Table = New ADOX.Table
Dim ADOXindex As ADOX.Index = New ADOX.Index
Dim oConnect As String
oConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FileName
Try
ADOXCatalog.Create(oConnect)
ADOXTable.Name = "tblContacts"
ADOXTable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
ADOXTable.Columns.Append("Nick", ADOX.DataTypeEnum.adVarChar, 64)
ADOXTable.Columns.Append("RealName", ADOX.DataTypeEnum.adVarChar, 64)
ADOXTable.Columns.Append("Age", ADOX.DataTypeEnum.adInteger)
ADOXTable.Columns.Append("BirthDate", ADOX.DataTypeEnum.adDate)
ADOXTable.Columns.Append("Address", ADOX.DataTypeEnum.adVarChar, 256)
ADOXTable.Columns.Append("PhoneNum", ADOX.DataTypeEnum.adVarChar, 32)
ADOXTable.Columns.Append("email1", ADOX.DataTypeEnum.adVarChar, 64)
ADOXTable.Columns.Append("email2", ADOX.DataTypeEnum.adVarChar, 64)
ADOXTable.Columns.Append("email3", ADOX.DataTypeEnum.adVarChar, 64)
ADOXTable.Columns.Append("Notes", ADOX.DataTypeEnum.adVarChar, 4096)
ADOXCatalog.Tables.Append(ADOXTable)
ADOXindex.Name = "IDindex"
ADOXindex.Columns.Append("ID")
ADOXTable.Indexes.Append(ADOXindex)
Catch ex As System.Runtime.InteropServices.COMException
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
Return False
Finally
ADOXCatalog = Nothing
End Try
Return True
End Function
End Class
the database gets created but when i open it using MS access 2007 it's empty.. no tables
|
|
|
|
|
I am having a problem dragging and dropping into a datagrid. I have the code, and it works for certain cells in the datagrid, but items that are dates or integers (as opposed to strings) the hittest does not work. Here's the code:
Private Sub DataGrid1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGrid1.DragDrop
Dim lbl As String = DirectCast(e.Data.GetData(GetType(String)), String)
Dim Index As Integer
TextBox1.Text = lbl
DataGrid1.BorderStyle = BorderStyle.Fixed3D
Dim pt As Point = DataGrid1.PointToClient(New Point(e.X, e.Y))
Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt.X, pt.Y)
hitRow = hti.Row
hitCol = hti.Column
If hti.Type = DataGrid.HitTestType.Cell Then
DataGrid1(hti.Row, hti.Column) = lbl
End If
Label6.Text = hitRow
Label7.Text = hitCol
Label9.Text = Me.DataGrid1(hti.Row, 8).ToString()
End Sub
Any ideas?
|
|
|
|
|
heeelloo to all plz help me out, i want to add records to recordset executing stored procedure , hw cn i do dt plzzzz its urgent
Thanks in Advance plzzzz
Parag
|
|
|
|
|
Why is there a sudden influx of people using VB6 ? It always sucked, it's long dead, why are you using it ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi all
I am trying to take an XML response from a web server and putting it into a Dataset
I am using a streamreader to pass the xml stream to the readxml method of the dataset, however I am finding that I am not getting all the data..
this might explain myself better.. if i do this:
HttpWebResponse oResp = (HttpWebResponse)myReq.GetResponse();
StreamReader oResultSR = new StreamReader(oResp.GetResponseStream(), encoding);
sMessage = oResultSR.ReadToEnd();
TextWriter tw = new StreamWriter(@"c:\hmmm.txt");
tw.WriteLine(sMessage);
tw.Close();
that works fine and my text file has all the xml data I need
however if i do this (which i want):
HttpWebResponse oResp = (HttpWebResponse)myReq.GetResponse();
StreamReader oResultSR = new StreamReader(oResp.GetResponseStream(), encoding);
DatasetXML[a].ReadXml(oResultSR);
DatasetXML[a].WriteXml(@"c:\hmmm.xml");
it only gives me the 1st node of the xml and not the rest
anyone know why?
|
|
|
|
|
sorry wrong forum meant to post in c# !
|
|
|
|
|
Is it possible to unload a loaded assembly in vb.net? Any help appreciated.
ty
|
|
|
|