|
I need a way of making list boxes center the values displayed within the list. I also need to find a way of making them unselectable without setting enabled to false or SelectionMode to None because the form won't load the way I tryed doing it if you know of another way please help me. |
| MigrationUser 1 Tuesday, June 03, 2003 2:49 PM |
Can anyone help me? I really need to get this program done and I don't want to have to switch to lots of labels |
| MigrationUser 1 Wednesday, June 11, 2003 4:55 PM |
Well, you can cheat and pad all of the strings with leading spaces... Other than that I don't think you really have a choice with using a listbox. You could use a Listview, in report (details) mode, with a first column of width = 1.
As for the selection mode property, setting it to none shouldn't cause an issue... What are you doing specifically that makes this not an option? |
| MigrationUser 1 Wednesday, June 11, 2003 6:39 PM |
I'd do listview if I could use a report but I have been unable to do so I can't seem to find how to add one to my project I go to add component and it is not in the list, I don't know why.
For SelectionMode I need to make it so no items in the list are selected and nothing can be selected by the user as well but it still needs to be displayed and setting enabled to false makes them gray which won't work either, if you know how to change it so that enabled=false could still have black text I'm open to suggestions. Any help at all is apreciated. |
| MigrationUser 1 Thursday, June 12, 2003 3:48 PM |
I still don't understand, though, why SelectionMode = None doesn't do what you want? It sounds like it precisely fits your needs.
As for finding the Listview, it should be on the toolbox like all of the other controls. You can right click on the toolbox and select Sort Items Alphabetically to make finding things a little easier. |
| MigrationUser 1 Friday, June 13, 2003 12:58 PM |
where is a good place to put the SelectionMode = None I've tryed setting it in design view and putting the code in events like form_Load but it always says there is some error with just that part. I just added list view to my toolbox it hadn't been displayed before heven't gotten a chance to try it yet though I'll post again once I have. |
| MigrationUser 1 Tuesday, June 17, 2003 4:51 PM |
Okay, definitely need some more information:
1- What is the error you are seeing? 2- As for the ListView not appearing in the Toolbox, is there anything out of the ordinary with your environment? It is considered one of the standard controls and should appear by default. Did, perchance, you or someone else remove from the toolbox? |
| MigrationUser 1 Tuesday, June 17, 2003 6:52 PM |
the error is:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot call this method when SelectionMode is SelectionMode.NONE.
As for ListView not having been in the toolbox I don't know why it wasn't there all I've done is add things to the toolbox haven't removed anything and no one else uses this computer let alone VB but myself. |
| MigrationUser 1 Wednesday, June 18, 2003 10:32 AM |
Is there anything else that should be in the toolbox to create a report that I might not have that could be causing some other problems I'm having? |
| MigrationUser 1 Wednesday, June 18, 2003 10:33 AM |
How do I make ListView display records from a databse anyway i just tryed it and can't figure out how? |
| MigrationUser 1 Wednesday, June 18, 2003 10:40 AM |
You can find some excellent examples on data binding <a href="http://windowsforms.com/Default.aspx?tabindex=3&tabid=40#Data">here</a>. |
| MigrationUser 1 Wednesday, June 18, 2003 1:15 PM |
Any suggestions on how to fix the error? Or on creating a report since mine doesn't want to give me that option? |
| MigrationUser 1 Wednesday, June 18, 2003 2:45 PM |
Well, I still don't think I have enough information... I can set SelectionMode just fine in a listbox. Are you doing anything else to the listbox? Are you setting the SelectedIndex anywhere?
As for the "report," can you set the View property to Details? |
| MigrationUser 1 Wednesday, June 18, 2003 3:15 PM |
I've tryed several ways of setting SelectionMode to none I get the same error each time although I noticed that the line where it had this problem was when I had the form name .show for some reason that is where the problem occured any thoughts on that?
For the report you want me to set its view property to details but i can't get a report its not in the list of items I can add I have no idea what I am doing wrong with that. |
| MigrationUser 1 Wednesday, June 18, 2003 4:36 PM |
Okay, the more that I participate in this thread, the more confused I get. Let's start over:
Problem 1- You have a Windows Forms application which contains a Form. On the form, you have a Listbox. The Listbox contains Items and you don't want the user to be able to select anything. However, setting SelectionMode = None results in an error.
Problem 2- Something to do with a Report and Listview. I honestly do not understand what you are trying with respect to this.
Regarding #1, can you post the following things: 1 - The code that you use to load the items into the listbox. 2- Any code you have put in the Constructor of the form upon which the Listbox resides. 3- Any code you have put in the Load event of the form upon which the Listbox resides. 4- A list of any properties of the Listbox whose value is not the default and what that value is.
Regarding #2, can you please explain a little more clearly what you are trying to do?
Hope we can get these problems worked out... Thanks. |
| MigrationUser 1 Wednesday, June 18, 2003 5:14 PM |
1-1 I set its list equal to a field in a databse from design view 1-2 Do you just want code involving the listbox or everything I don't understand your question? 1-3 none unless I try for SelectionMode=None 1-4 haven't changed much but here it is: DataSource=DsCName.TS DisplayMember=CName ValueMember=CName Name=lstCName
2 The entire reason I went with list boxes is because I couldn't do a report. I was told that I could add one by going to add item and selecting Crystal Report but I don't have this as an option or any kind of report. I'd prefer to have a report over listboxes because the way this is set up now isn't great especially printing. As for ListView you brought that up in one of your earlier posts. |
| MigrationUser 1 Thursday, June 19, 2003 8:38 AM |
Okay, I guess the first thing to try is add this code to your form:
Private m_ActivateOnce As Boolean = False Protected Overrides OnActivated(ByVal e As EventArgs) If Not m_ActivateOnce Then m_ActivateOnce = True MyListbox1.SelectionMode = SelectionMode.None End If MyBase.OnActivated(e) End Sub
I guess there is something wrong with setting the SelectionMode property while binding... Maybe this will work though as it occurs after the bind has taken place.
re 1-2: I was thinking that if you had something odd in your constructor beyond the following:
Public Sub New() MyBase.New() InitializeComponent() End Sub
That whatever odd stuff you had in their could cause the problem... Do you have a whole lot of stuff in your constructor?
re 2 - What version of VB are you using? Standard? Enterprise? |
| MigrationUser 1 Thursday, June 19, 2003 1:05 PM |
I copied the code but it doesn't seem to like it, VB did its little blue underline thing on almost everything starting with Overrides for that one it says- 'Overrides' is not valid on a member variable declaration. any reason why this code isn't working? Is there a specific spot in the code where i have to put it to make it run properly?
Sorry if this sounds stupid but what is the constructor? if its what I think it is which is just the code from the form designer that creates the control then nothing is out of the ordinary other than that i don't know.
I am using the standard version of VB is that why i can't create a report? If it is then Microsoft is stupider then I thought.
|
| MigrationUser 1 Thursday, June 19, 2003 2:57 PM |
Ah, my code has bug in it ;) It should read like this:
Private m_ActivateOnce As Boolean = False
Protected Overrides Sub OnActivated(ByVal e As EventArgs) If Not m_ActivateOnce Then m_ActivateOnce = True MyListbox1.SelectionMode = SelectionMode.None End If MyBase.OnActivated(e) End Sub
and, make you sure you replace "MyListbox1" with the name of your Listbox.
The constructor is "Public Sub New" It is the method used to create a new instance of an object.
I honestly don't know if the Crystal Reports components are included in the standard edition or not... Perhaps someone else can chime in with the answer to this one. |
| MigrationUser 1 Thursday, June 19, 2003 5:04 PM |
1. Your code seems OK now but I'm getting the same error as before on the line where it sets SelectionMode to None.
2. As for the constructor the only other code in there related to the list is the databinding
For the Crystal Reports part of it I wish Microsoft would email me back I've sent them several emails and still nothing basides automated response, which doesn't help. I think they want me to email them the other way where it ends up costing me money for something that I can safely blame on them for either messing up my version somehow or not including the Crystal Reports components in Standard but being nice enough to leave the help files there.
Anyway can you think of any reason why this doesn't like SelectionMode.None? |
| MigrationUser 1 Friday, June 20, 2003 8:49 AM |
My guess it that databinding requires the ability to "select." That's the only thing I can come up with... Thus, you will need to come up with a different method to restrict selection. You could try handling the click event of the listbox and setting the SelectedIndex = -1. Perhaps that'll take care of it.. |
| MigrationUser 1 Friday, June 20, 2003 10:19 AM |
OK thank you I'll see what I can come up with unfortunatelt for me my entire program is now deciding it doesn't feel like working but I won't bother you with that I'll figure it out myself. I have also decided that Standard does come with Crystal Reports because they mention it on the box so if it doesn't come with it I'm pretty sure thats false advertising or something. |
| MigrationUser 1 Friday, June 20, 2003 11:12 AM |