|
Okay, first point (based on documentation, which is a bit confusing after your observations)
CheckedListBox.DataSource Property
Gets or sets the data source for the control. This property is not relevant for this class
Back to your question, instead of MoveNext (which doesn't exist) you could use the indexer of Items property (well actually indexer of the ListBox.ObjectCollection class)
In VB I recall that the syntax is
cboMyTable.Item(counter)
However you could also modify the SQL statement so that you don't loop each item in the listbox, but instead you first get all the records and then match them to items. In this case you would use SQL statement like
SELECT ID, OtherID FROM tblMANYTOMANY WHERE OtherID=65
and then fill a datatable based on that and for each row found in datatable, check the corresponding item in the listbox. Although you mentioned that modifying the query wasn't the first option, this would significantly bring scalability to database operations especially if you plan to upgrade to server side database such as SQL Server
Hope this helps,
Mika
|
|
|
|
|
Hi Mika, unfortunately that didn't work.
To make it easier, and forgetting database access for a while, I can narrow it down to the following issue. Hopefully this might help you to find the root of the problem, and to identify where I'm going wrong!!!
The problem is that I have searched through the listbox properties, and cannot find a way of getting the tags from each of the items in a listbox through a FOR loop. What I would like to do is something like this:
Dim i as integer = 0<br />
<br />
For i = 0 to (MyListBox.items.count - 1)<br />
<br />
' Attempt 1 - doesn't work (Tag isn't a property of Items anyway)<br />
<br />
msgbox("The tag in this item is: " & MyListBox.Items.Tag(i))<br />
<br />
' Attempt 2 - doesn't work either (Tag is a property of the listbox, but it<br />
does not seem to like being treated as an "array")<br />
<br />
msgbox("The tag in this item is: " & MyListBox.Tag(i))<br />
<br />
Next
In both cases, the application compiles but returns an error message: "If a member in a class library has been removed, recompile any assemblies that reference that library". I am not certain what this means, but I'm guessing it is the fact that listboxes don't like their items being treated as "arrays".
I have also changed i = 0 to i = 1 in the forlorn hope that the listbox started at 1 rather than 0, but with no luck.
I'm sure there are ways around this, but I don't want to write pages of extra code if I'm just missing one line...
Thanks again, I really appreciate it!
|
|
|
|
|
I should also point out that it's a CheckedListBox, not a ListBox (hence the "checks")
|
|
|
|
|
Hi,
I've managed to fix this problem, after much gnashing of teeth...
Basically, for anyone else who runs into the same problem, here is a simple example showing how tags for items in a checkedlistbox can be displayed:
Dim n as Integer<br />
<br />
Dim str as String = ""<br />
<br />
For n = 0 to (MyCheckedListBox.Rows.Count - 1)<br />
<br />
str = str & MyCheckedListBox.Items(n)("MyTag").ToString() & " "<br />
<br />
Next<br />
<br />
Messagebox.show(str)
This assumes you have set up the tag for the item somewhere else in your code, e.g. if it's from a datatable:
MyCheckedListBox.DataSource = dtMyDataTable<br />
MyCheckedListBox.DataBindings.Add("Tag", dtMyDataTable, "MyTag")<br />
MyCheckedListBox.DataBindings.Add("Text", dtMyDataTable, "MyText")<br />
MyCheckedListBox.DisplayMember = "MyText"
To be honest, this seems a very clunky way of doing things, but that's just my opinion!
|
|
|
|
|
Doesn't seem so clunky at all.
As you noticed the problem in your previous post was that you didn't use the indexer on Items, but tried to use it on Tag property (which won't work since you are not "positioned" to any single Item).
Glad you got it solved.
Mika
|
|
|
|
|
hi to everybody, I would need an information please.
I need to distribute an application on a pendrive and
my customer doesn't want to make installations
but the problem is that I must give him a report and
I cannot use the cristal report viewer because it asks for the dll to install.
if I use the control "rdlc" for the construction of the report,
as do I do to show it without bringing me behind particular dll?
thanks for the help and good day
|
|
|
|
|
You simply don't have a choice. You either make an installation, as required by whatever reporting package you use, or you leave out the reporting. It's that simple.
|
|
|
|
|
I declared a variable name as string
I populate my combo in the selected indexchanged event
i have name = me.combox.selecteditem tostring
the name is returning system.data.datarowview
Any idea why is returning system.data.datarowview type instead of assigning
the selected name to the name variable.
|
|
|
|
|
I am confused.
Post your code please.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Sub listsponsor()
Me.CmbSponsor.DataSource = objreg.listsponsor
Me.CmbSponsor.DisplayMember = "distID"
Me.CmbSponsor.ValueMember = "distID"
End Sub
Private Sub CmbSponsor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbSponsor.SelectedIndexChanged
Me.txtsponsorformno.Text = objreg.getsponsorformno(Me.CmbSponsor.SelectedItem.ToString)
End Sub
Me.CmbSponsor.SelectedItem.ToString returns system.data.datarow view. i also notice on step into that selectedindexchange fire bfore line 2 in sub listsponsor
|
|
|
|
|
Ebube wrote: Me.CmbSponsor.SelectedItem.ToString returns system.data.datarow view
Its due to the fact that your ComboBox is Databound.
Use SelectedText instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I have an ASP (classic) application, I want to call MQ series from this application. Does anyone has sample code to do this.
Issue in detail: I have 5 fields in my ASP application, when the user enters data to this field I have to validate by putting these values to MQ series queue.
If somebody can help on this it would be great.
Asheej T K
Bangalore
asheejtk@yahoo.com
|
|
|
|
|
Hi
Please tell me how we use INF Tool for making setup of any VB6 project
Amit Battan Ror
battan20@gmail.com
|
|
|
|
|
Amit Battan Ror wrote: Please tell me how we use INF Tool for making setup of any VB6 project
Look at its documentation.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I have one arraylist
where i load up all bookinfo obj
and want to return the collection of bookinfo[]
I can do it the following way in c# but I need to know how can we type cast the following in vb.net:
ArrayList a=new ArrayList();
Bookinfo obj=new BookInfo();
return (BookInfo[])a.ToArray(obj.GetType());
|
|
|
|
|
I think thi will do it :-
Dim a As New ArrayList()
Dim obj As Bookinfo = New BookInfo()
Return DirectCast(a.ToArray(obj.[GetType]()), BookInfo())
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
|
Unless you are stuck with framework 1, don't use ArrayList at all.
Use a generic list. As it's strongly typed you don't need any casting:
List<Bookinfo> a = new List<Bookinfo>();<br />
Bookinfo b = new Bookinfo();<br />
a.Add(b);<br />
return a.ToArray();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi all URGENT!!!
I posted this a long time ago and did not get any answers. can someone please help!!!
I have a vb.net datagridview. One col has a combobox, I want to populate another cell from within the same row as the ComboBox is based on the ComboBox selection.
Eg. ComboBox.Selectedtext="Yes" then DGV.DateGiven = date.today
Can someone please help me how to do this.
modified on Tuesday, November 25, 2008 7:59 PM
|
|
|
|
|
|
Dim dtDate(table.Rows.Count) as DateTime
Dim iValue(table.Rows.Count) as Integer
For row as Integer = 0 To table.Rows.Count
dtDate(row) = table.Rows(row).Item("DateColumn")
iValue(row) = table.Rows(row).Item("ValueColumn")
Next
Basically you keep recreating your arrays within the For..Next code block.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
This is a great suggestion, and similar to what I was doing.
The down side is that this array needs to be used by a different procedure and once I have gone out of scope in the dataset procedure the Arrays are empty when I get to the procedure they are to be used in.
THX
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Dim objStreamWriter2 As StreamWriter
Dim DTString As String
DTString = "C:\ETCLINK\" + Convert.ToString(Date.Now)
'Pass the file path and the file name to the StreamWriter constructor.
objStreamWriter2 = New StreamWriter(DTString)
I take a runtime error when the code is run. What is the problem? Thank you?
(objStreamWriter2 = New StreamWriter("C:\ETCLINK\09042008121212.txt") no problem here
|
|
|
|
|
Hmm.
Check out "DTString". When run it could be set to:
C:\ETCLINK\2001-01-01 11:11
This isnt a valid filename... The colon symbol ( : ) is a bad char.
|
|
|
|
|
I would concur with the other reply, although if you actually gave us the error message, we could provide a better answer.
If the problem is the resulting string from Date.Now, use the Format command to get the resulting string into the desired format.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|