|
Your problem with that is what you thought it was. frm only knows about the controls added directly to it. Containers have their own controls and the object that the container is added to knows nothing directly about it's children.
You can access it through Me.TabPage1 because it's a variable that was declared within the form, but it was never added to the forms control collection, it was added to the tabControl's control collection.
If you want to be able to search through children controls as well, you could do that using a modified version of what I posted earlier.
Public Shared Function getControlArray(ByVal baseControl As Control, _
ByVal controlName As String, _
ByVal TypeToReturn As Type, _
Optional ByVal separator As String = "") As Control()
Dim aList As New ArrayList
For Each ctrl As Control In baseControl.Controls
If ctrl.Controls.Count > 0 Then
For Each item As Control In getControlArray(ctrl, controlName, TypeToReturn, separator)
aList.Add(item)
Next
End If
If ctrl.Name.ToLower.StartsWith(controlName.ToLower & separator) And _
ctrl.GetType = TypeToReturn Then
aList.Add(ctrl)
End If
Next
Return aList.ToArray(TypeToReturn)
End Function
I just made the Form being passed in a Control instead and check that control for any children, then it recursively checks the children. I tested it by adding a TabControl and several Labels to a TabPage and it works as expected.
You can also just pass in the TabPage if you know that the items will only be on that TabPage.
|
|
|
|
|
|
How are you trying to do this at the moment?
Where is it failing?
Why are you trying to 'pinch' a captcha, there are numerous articles on how to produce your own.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Hi..all Codeproject members...
I got a vb.net code i got from codeproject..
this code is a class to load a sqldatareader into a listview
and this is the code
Imports System.Data.SqlClient
Public Class ListViewData
Public Sub FillListView(ByRef MyListView As ListView, _
ByRef myData As SqlDataReader)
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim shtCntr As Short
MyListView.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
'If shtCntr = 1 Then Continue For
lvwColumn = New ColumnHeader()
lvwColumn.Text = myData.GetName(shtCntr)
MyListView.Columns.Add(lvwColumn)
If shtCntr = 0 Then lvwColumn.Width = 125
If shtCntr = 1 Then lvwColumn.Width = 300
Next
Do While myData.Read
itmListItem = New ListViewItem()
itmListItem.Text = myData(0)
For shtCntr = 1 To myData.FieldCount() - 1
'If shtCntr = 1 Then Continue For
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetString(shtCntr))
End If
Next shtCntr
MyListView.Items.Add(itmListItem)
Loop
End Sub
End Class
And this is how i use this code
Private Sub Usage_ListItem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As SqlConnection = New SqlConnection(constr)
Dim query As String
query = "SELECT ItemCode [Item Code], ItemName[Item Name] FROM IC_ITEMS"
con.Open()
Dim comtext As SqlCommand = New SqlCommand()
comtext.Connection = con
comtext.CommandText = query
Dim reader As SqlDataReader
reader = comtext.ExecuteReader
Dim testlist As ListViewData = New ListViewData
testlist.FillListView(ListView1, reader)
comtext = Nothing
con.Close()
End Sub
The problem is i just want to load only ItemName Reader into the listview..
how can i modify this code
at least
thx for codeproject members attention..
|
|
|
|
|
Your best bet is to ask this on the forum of the article where you got the code.
But I'll take as stab at it.
If you only want the itemname column in your listview then all you have to do is change your SQL statement
from:
"SELECT ItemCode [Item Code], ItemName[Item Name] FROM IC_ITEMS"
to:
"SELECT ItemName[Item Name] FROM IC_ITEMS"
and you should have only your itemname column in the listview
|
|
|
|
|
i mean i want to use the itemcode into another control
|
|
|
|
|
If you want to use the different items in different controls, then something like this:
reader = comtext.ExecuteReader
Dim itemCodeIndex, itemNameIndex As Integer
itemCodeIndex = reader.GetOrdinal("ItemCode")
itemNameIndex = reader.GetOrdinal("ItemName")
While reader.Read()
ListView1.Items.Add(reader.GetValue(itemCodeIndex))
ListView2.Items.Add(reader.GetValue(itemNameIndex))
End While
|
|
|
|
|
and how is i have 3 reader and i want use 2 reader into list view 1
and 1 reader into listview2
|
|
|
|
|
I don't understand your question
|
|
|
|
|
ok...this all completely done...thx
|
|
|
|
|
Dear Administrator,
My problem is as follows :
My PM has asked me to create a new button with the name "Tasks" on the Outlook page. When this button is pressed , the control should go to a form containing details regarding the tasks to be performed by the employees.
I have created the necessary form by using Visual Basic Express Edition.
The form is also supposed to have a "send" button.
When the "send" button is pressed, the details should be stored in the database and Outlook Page has to come up.
When I click the "Tasks" button in the outlook page once again, the control should go to the same form containing all the details.
Any changes made in the form are to be saved in the database and when the "send" button on the form is pressed, the control has to again come back to the Outlook page.
This is the problem. I am using Visual Basic Express Edition for creating this facility.
Please tell me the procedure as to how to do this work.
Actually, I am working as a Design and Development Engineer in TATA ELXSI. Please answer to my message as quickly as possible. I have to release the product before the second week of June.
Regards,
Suragala Srinivasa Rao,
Design and Development Engineer,
TATA ELXSI LIMITED,
Technopark, Trivandrum-695581, Kerala, India.
Cell Number : 9037595866
Email address : suragalarao@tataelxsi.co.in
|
|
|
|
|
S.Srinivasa Rao wrote: Design and Development Engineer,
This does not sit easy with Express Edition!
However, Cookies could be your friend on this problem.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
S.Srinivasa Rao wrote: Dear Administrator,
There only a few administrators here and not many of them check these forums.
S.Srinivasa Rao wrote: Please tell me the procedure as to how to do this work.
Nobody is going to just give you a complete solution for this, do your own work, research, ... that's what you get paid to do.
S.Srinivasa Rao wrote: Suragala Srinivasa Rao,
Design and Development Engineer,
TATA ELXSI LIMITED,
[adres removed]
Cell Number : [removed]
Email address : [removed]
You must really like spam.
NEVER post your email adres on a public forum, same goes for your phone number and adres.
Nobody is going to contact you using them so remove them from your message.
|
|
|
|
|
S.Srinivasa Rao wrote: I have to release the product before the second week of June.
I'd suggest to wait with the release until the product is "working".
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: wait with the release until the product is "working"
That is not an entrepreneurial spirit; release dates should be upheld. Turnover has to ramp up.
Change the bloody specs if you must. Cripple it, save some for the next release.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Luc Pattyn wrote: That is not an entrepreneurial spirit; release dates should be upheld. Turnover has to ramp up.Change the bloody specs if you must. Cripple it, save some for the next release.
I know, it's a common attitude. I'm imagining a large-mouthed tie, explaining the cook that one has to serve the eggs on time, even if they are rotten and it would kill the customer.
I are Troll
|
|
|
|
|
Hello, this is Vikash Gohil.
I have Created a Windows Service which does the following when service is started :
Connects SQL Server 2000 Database.
Starts a Threads.
Thread executes a while loop
In the while loop,
Current system time is taken using : format(now,"HH:mm")
A Query is made to a Table in Database to look for records as below.
"Select <FieldName> From <tableName> Where <FieldName>='" & format(now,"HH:mm") & "'"
if any record exists, then a particular procedure gets executed.
The above code continues to run in a while loop 24/7
The problem I am facing is, the service takes aroung 98% CPU Usage.
The Database Table contains only 20 to 25 records.
I want to know why this thing is happening.
Is it bcoz of the while loop. If yes, then what to use instead of while loop?
I Can't change the Service functionality as it is a client requirement.
Please can anyone guide me in this matter.
Any help would be greatly appreciated.
Thanks in Advance, awaiting a reply soon.
|
|
|
|
|
Consider using System.Threading.Thread.Sleep( int milliseconds ) .
That should unburden the processor.
Cheers
I don't like my signature at all
|
|
|
|
|
Hello, Estys.
Thanks for your reply.
I thought of using Sleep.
But many posts on the net suggest that using Sleep is a bad practice.
So is there any risks or disadvantages in using Sleep.
Please reply if you know anything about this.
Thanks Again.
|
|
|
|
|
VikashGohil wrote: But many posts on the net suggest that using Sleep is a bad practice.
Many things are 'Bad Practice' but they still get done.
Have you never used a GOTO?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Hello, Dalek.
Thanks for Reply.
I will surely try using Sleep.
Thanks.
|
|
|
|
|
Well, using Sleep in a UI thread is a nuisance to the user because it blocks interaction.
In this case, being a background service (no UI), it's not a bad way to go.
Unless you can get rid of the necessity of periodically polling for changes in you database, you must release the processor. You seem to use a busywait loop which utilizes the CPU to its capacity doing nothing at all (most of the time).
Alternatively you could try some sort of timer.
Cheers
I don't like my signature at all
|
|
|
|
|
I Don't think you have any while loop problem. The problem could be that connecting with SQL Server 2000 Database. At the initial state it takes (connecting with SQL Server 2000) long time bcoz sql server is just starting. Try finding to sql server running state and then connect with that. Sleep is not an good idea.
|
|
|
|
|
Hello everybody,
this might sound like a simple question, but after searching more information on the web I couldn't find any useful stuff. Maybe someone here knows the approach to use?
I have a picturebox in which I load an image in "normal" mode (the image is supposed to keep its original size). The image will always be aligned on the left side of the picture box... BUT I NEED it right-aligned! Is there a (simple) way to do this, e.g. like a "dockmode" to dock the image to one side of the picture box? The "normal" mode seems to place the image to (0;0) coordinates by default - is there a way to change that default behaviour?
Thank you
Michael
modified on Wednesday, May 26, 2010 1:36 PM
|
|
|
|
|
Possibly resolved...? I just don't know if that's the most elegant method, also considering performance issues...
Here's how I'm currently doing it:
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If PictureBox1.Image IsNot Nothing Then
Dim g As Graphics = e.Graphics
g.DrawImage(PictureBox1.Image, PictureBox1.Width - PictureBox1.Image.Width, 0)
End If
End Sub Any hints or constructive criticism around ?
|
|
|
|