|
Puneet Bhatnagar wrote: DesiredTask: I want to add both these strings to 0th Index of cboProject and at the same point of time hide the text followed by "," i.e hide India.
You would have to create a multi-column combo box for this. A simple search brings me to this[^] article on CP.
|
|
|
|
|
If you only need two columns and one will always be hidden you could try the following:
create a datatable with 2 columns
fill the datatable with the data you want
assing the datatable to the cboproject.datasource property
assing the cboproject.valuemember property to the columnname from the column to be hidden
assing the cboproject.displaymember to the columnname from the column to be shown
The multi column combobox mentioned by ChandraRam could give you more options tho.
|
|
|
|
|
Hi,
Thanks for your help and time. However still I am facing some problem. Please find below my code.
Try
Dim sql As String
Dim DB2conn As DB2Connection
Dim ds As New DataSet
DB2conn = New DB2Connection("server=" & ServerAddress & ";database= " & sDBName & ";Connect Timeout=30;user Id=" & UName & ";password =" & pwd &)
Dim DB2Cmd As New DB2Command
sql = "Select * from ProjectMaster"
DB2conn.Open()
Dim DB2DA As New DB2DataAdapter(sql, DB2conn)
DB2Cmd = New DB2Command(sql, DB2conn, DB2trans)
DB2DA.Fill(ds)
ComboBox2.DataSource = ds.Tables(0)
ComboBox2.DisplayMember = "ProjectMaster.ReleaseNumber"
<b>Me.ComboBox2.ValueMember = "ProjectMaster.ProjectID"</b>
Catch ex As Exception
MessageBox.Show(ex.Message + " " + ex.Source)
Finally
DB2conn.Close()
End Try
The code is breaking at line (ComboBox2.ValueMember = "ProjectMaster.ProjectID"), in bold in code snippet. Please let me know where I am going wrong.
Again Thanks for your efforts.
|
|
|
|
|
First a Select * isn't adviced (but is not the cause of the error)
You don't need to use the tablename before the columname I'm not shure but I think that is what causing the problem (the combobox can't find that column) so try changing the line to :
me.combobox2.displaymember = "ReleaseNumber"
me.combobox2.valuemember = "ProjectID"
If that doesn't help make shure the datatable has these 2 columns (debug and visualy confirm it) with the correct names
|
|
|
|
|
Hi,
I tried with all your suggestions however it is still not working. Please let me know what shall I do?
Thanks & regards
Puneet
|
|
|
|
|
what is the error message you are getting?
|
|
|
|
|
"Could Not Bind To The New Display Member,
Parameter Name: New Display Member"
|
|
|
|
|
If you use string3 = string1 + string2 you won't be able to hide the second string.
You need to put the strings into an object that has two fields and add this object to the ComboBox. You could then use the DisplayMember property to show only the first field. Alternatively, you could override the ToString() function to display only the first field.
Something like the following should do it.
Public Class TheData
'Public for simplicity but should be properties
Public firstString As String
Public secondString As Sting
Public Overrides Function ToString() As String
return firstString
End Function
End Class
In your code to populate the combobox you would need something like this.
Dim d As TheData = new TheData()
d.firstString = "Puneet"
d.secondString = "India"
me.cboProject.Items.Insert(0, d) ' or me.cboProject.Items.Add(d)
There might be an easier way but I can't think of one (it's a breeze in MS Access because the combobox control has multiple columns that you can show or hide.)
David Rice
|
|
|
|
|
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
|
|
|
|