|
does not work
get this error
boolean is a type and cannot use a an expression.
|
|
|
|
|
Hi, I don't know how to do this in VB.NET; I suggest you ask again in the VB/VB.NET forum.
In C# it would be: if(myVar is boolean) {...}
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have webbrowser control and a tool menu. There is a button in the tool menu that when clicked, the webbrowser should surround the selected text with a "<code>" tag. Do you have any idea how can i do this ?
|
|
|
|
|
Hello All,
I am fairly new to VB and I am trying to load a user control (with a few text boxes - nothing special) using the built in snippet:
Dim myAssets As New UserControlAssets()
With myAssets
.Location = New Point(64, 40)
.Size = New Size(668, 488)
.TabIndex = 0
End With
Try
Me.ParentForm.Controls.Item("panelMiddle").Controls.Add(myAssets)
Catch nrx As NullReferenceException
Debug.Print("Apparently its NULL.")
End Try
This is the exception. I have tried variations of different controls, even a listview. I am missing something vital, and I've spent so much time on this. If you cant see the problem from the code but have a clue please respond and I will provide additional data.
Regards,
H. Venn
|
|
|
|
|
You will need to narrow down what part of the following statement is null:
Me.ParentForm.Controls.Item("panelMiddle").Controls.Add(myAssets)
If ParentForm is null, then that's your problem. The other (and more likely) location would be Item("panelMiddle").
Where is this code being executed? If Me is the form that contains the panelMiddle control, then you don't need the ParentForm portion of that code.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thankyou, Tom.
The code indeed references the panel incorrectly. I have altered it to
Try<br />
Me.Controls.Item("panelMiddle").Controls.Add(myAssets)<br />
which does work better - it doesn't throw an exception. However, my user control flashes in the viewport for a few milliseconds and is gone. It is also inside the area of the parent form, which seems strange because when I use the code with a stock control it works. I am guessing that because it is a user control I may need some code in its class, however I cannot find any clues. I tried calling myUserControl.Validate() and CreateControl() to no avail. However the information you gave me was crucial. Looking at the code I assumed it was obtaining the reference for panelMiddle from the ParentForm - however the "Me" is like this in C++ so I see why this confuses it.
Cheers,
Henry
|
|
|
|
|
Can you please include more code? It's really hard to tell what is going on from a single line of code.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hey Tom
Sorry there's not much to it really - here:
<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
Dim myAssets As New UserControlIncome()<br />
With myAssets<br />
.Location = New Point(64, 40)<br />
.Size = New Size(100, 20)<br />
.TabIndex = 0<br />
End With<br />
Try<br />
' Original Code causing error: <br />
' Me.ParentForm.Controls.Item("panelMiddle").Controls.Add(myAssets)<br />
<br />
Me.Controls.Item("panelMiddle").Controls.Add(myAssets)<br />
' this doesn't work: Me.Controls.Item("panelMiddle").Show()<br />
Catch nrx As NullReferenceException<br />
Debug.Print(" NULL ref putting user control on panel")<br />
<br />
Catch ex4 As Exception<br />
Debug.Print("Exception - plian vanilla")<br />
End Try<br />
The user control I created using VS8 and even if it is a blank "form" it only flashes on screen for a few seconds. Like I said, if I use a text control, or listview or something, it stays. I've looked at what I can on user controls but all the doc'n I can find deals with the designer - i.e. compile time. (note: the controls work perfectly if I place them on a form, make it invisible and then show it when I need to, but this is a kludge I do not need I feel).
Thanks for your help so far - I am in a position where I am finishing uni and really need to find a team I can work with so I don't get bogged down for so long on these kinds of errors.
Regards,
Henry
ps When I use a textbox or another pre-packaged MS control it is placed correctly on the panel, however when the user control briefly flashes on screen it is out of bounds of the panel, I think at the Point (64,40) of the parent form
|
|
|
|
|
You may need to add the user control to the panel first then update it's Location/Size. If I create a Form in Visual Studio with a Panel that contains a single text box then the designer code loooks like this:
private void InitializeComponent() {
this.panel1 = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(39, 58);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 0;
this.textBox1.Location = new System.Drawing.Point(35, 37);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
As you can see the TextBox is added to the panel before it's properties are set. Also, make sure to assign a name to your user control. I can't remember off the top of my head, but there are some problems if you don't.
Assuming this doesn't help, if you can put together a small sample project and email it over then I'll be able to figure out the problem a lot quicker.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hmmm... thanks again Tom. I built a project to send to you, and it has helped - I think that the user control IS there, however it is hidden beneath a flow layout panel, which I used to structure the entire GUI. Still having the same problem however: the user control sticks to the main window, while a Windows control goes where I ask it, and stays on the panel...
Will experiment a bit more. I can send you the project if a solution doesn't present itself, however I feel that its something to do with addressing the panel - but that does not explain the placement.
Hold the press! I solved it - here's how, and also what surprised me:
It was the sizing, like you said, because the user control would only stay on the screen if I chopped off the "With Events" clause. So I reproduced the problem in a brand new project with a main form, containing 2 panels and 2 buttons, and a user control with a label on it. Embarrassingly, the reason the control was being placed on the panel was some old code in a "Finally" clause - silly me. What surprised me is that a call to clear the panel is only required for a flow layout panel - if not, it will place the next control at the right of any existing user control. Flow layout...maybe I should not be surprised!
Thanks once again - it took awhile but I got there!
Henry
|
|
|
|
|
Er...no I didn't. It worked in the test project, but the real application has a regular panel placed inside a flow layout panel, and it doesn't throw an error....
....10 minutes later....
<br />
panelFlowLeft.Controls.Item("panelRight").Controls.Add(myUC)<br />
That works. The confusion was the flow layout control - the panel could not be referenced as an item of the main form, because it was 3 levels deep. Pretty simple huh? Well - its all learning, and the idea to create a new project is not a new one, but perhaps I can make a rule: if I take more than 20 minutes on an apparently simple problem that should work, isolate, and recreate!
Happy Coding!
|
|
|
|
|
Hi !
How to embedding an Access table into datagrid (C#). After input data in datagrid, then click button save, it's will insert data on datagrid into Access database.
Thanks!
|
|
|
|
|
Just use a datagrid. After data is input, then you need to code the saving code on the save button. Not much else we can help you with since you did not give any real information about database schema, etc.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I'm busy on a record layout editor for flat file exports. I have a 'preview' window where the user can view a sample of the expected output, the sample being one line for each record type in each grouping. I would like to allow the user to scroll each line left and right, but independently, and would like suggestions on how to achieve this.
I think to keep it simple, I can use a fixed width font and manage a collection of start and end columns for each displayed line, then just render to a textbox the visible portions of each line. Getting more complicated, I could use a lightweight textbox for each line, with an 'invisible horizontal scrollbar', but unless it's as easy as it looks, I think I would be heading down a long, dark path there.
Any other suggestions?
|
|
|
|
|
Hi,
in order to show line oriented text I tend to prefer a ListBox.
If you choose a UserDrawn DrawMode, and implement DrawItem event handler, you could have
each line scroll the way you like.
IMO it is not necessary to select a non-proportional font (although I often do).
Not sure though how you would control the scroll amount...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thank you Luc!
You've given me an inspiration that took a few hours to crystallise. I can get the best of both worlds by using a ListBox for my basic line editing, and implement my own character based scrolling. As all my exports are text files, I don't need more than character scrolling for full WSYIWYG.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You know I spend too much thought on solving business problems, that I lose touch with the technical sides of things. Just thinking about even character based scrolling is taxing my brain, and years ago I did so much of it from scratch. I suppose some block paper and scribblings will evoke a flood of DOS memories.
|
|
|
|
|
I see two ways to do character based scrolling:
1. without user drawing: just give a variable substring to the ListBox item
2. with user drawing: use a variable x position and paint the entire string, parts of it
will end up outside the drawing area resulting in a scroll effect
BTW: DOS memories will not suffice for .NET applications...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'm going with #1 on this, but thanks for #2. I've never ventured into user drawing to draw anything, only to change colours.
|
|
|
|
|
I'm trying to get and set the state of multiple groups of radio buttons. Each group has 6 radiobuttons. I need to load and save the configuration of the groups- which one is checked. I've tried reading the Control->Item[i] in the panel, but do not see how to read which button is set or how to set it after reading a config file. The names of each can be read, but how can the Checked parameter be retrieved. Is there a way to get at that data without having to have a handler for each one and waiting for the stateChanged event?
|
|
|
|
|
Hi, this is how I handle groups of radio buttons:
1. design them all unchecked
2. assign them all (within one group) the same CheckedChanged handler
3. in the CheckedChanged handler, use "object sender" to identify the rb; store it somewhere
(maybe a class variable, maybe the Tag of the GroupBox,...)
4. in the form constructor or the Load handler: determine which rb needs to be checked,
and check it
5. in the form close handler: save the name of the currently selected rb (from the variable
or Tag in 3.)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the quick answer Luc.
What about loading the configuration later, after the constructor? I'm dealing with several hundred groups, and creating each of them individually is less than optimal. I'd like to store a radiobutton configuration in a config file (or several config files) and load them in on demand. I've been struggling trying to figure out how to set the Checked property through code after referencing the items through:
this->get_Controls()->get_Item(j)->get_Controls()->get_Item(i))
Item(j) is the group, Item(i) is the radioButton. Can the checked property can be set this way or similar? The order is the same for each group, so it's relatively easy to read the checked radioButton.
|
|
|
|
|
Hi Steve,
I trust it can.
You will have to cast to RadioButton before you can access the Checked property.
And I would prefer to split the line in two, one get_Item() per line seems more than enough
to me; I expect there too it will need a cast, don't know for sure what type get_Item returns,
if it is too general (such as object) it definitely needs a cast.
Read the documentation on that, and try it!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks again Luc,
I got it to work. It will certainly make life a lot easier.
I created a ControlCollection to hold the get_Controls() and after checking to make sure the item is a radiobutton cast the item to a radiobutton and used set_Checked() to set its value. It works like a charm!
|
|
|
|
|