Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
L

Lucy

@Lucy
About
Posts
30
Topics
11
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Finding an item in a listview
    L Lucy

    Hi thank you for the link. I was trying to go about this a different way but I found the answer before your reply using trial and error, Here is my form load event and the last if statement finds the item: RegistryKey key = Registry.LocalMachine.OpenSubKey("RegKey_test", true); RegistryKey k = key.OpenSubKey("Classification"); if (k != null) { string[] names = k.GetValueNames(); for (int i = 0; i < k.ValueCount; i++) { int values = Convert.ToInt32(k.GetValue(names[i], "")); ListViewItem item1 = new ListViewItem(); ListViewItem.ListViewSubItem item2 = new ListViewItem.ListViewSubItem(); item1.Text = names[i]; item2.Text = Convert.ToString(values); item1.SubItems.Add(item2); listView1.Items.Add(item1); } } if (key.GetValue("Threshold") != null) { string KeyValue = Convert.ToString(key.GetValue("Threshold", "")); ListViewItem itemFind = listView1.FindItemWithText(KeyValue, true, 0); if (itemFind != null) { itemFind.Selected = true; listView1.FocusedItem = itemFind; } } I am not sure if this is user friendly yet as the second column of the listview may be taken out so that the values cannot be seen by the user. I would then need a new ways to find the value needed to select the appropriate item. Lucy

    C# question

  • Finding an item in a listview
    L Lucy

    Hi I have a listview on my windows form with a details view. The listview has to columns and many items. These items and subitems are add to the listview in the form load event. The item are also put in s specific order. I then want to find an item in the second column and then select this item and give it focus. Can anyone give me any suggestions or where I can find good examples of listviews? Lucy

    C# question

  • Select an item in a listview
    L Lucy

    Thank you! It is now clear to me the difference between selected and focused. To solve my problem I put this code under the selected item code in the form load event: listView1.FocusedItem = listView1.Items[2]; All works fine now. Thanks again. Lucy

    C# help database question

  • Select an item in a listview
    L Lucy

    I have just added a listview onto a windows form. I have added 1 column to the listview and 4 items. I then set the View property to details. In the form load event of the windows form, I set the selected item to index 2 (item3) like this: listView1.Items[2].Selected = true; When the form loads item3 is selected as its back colour is blue but the first item has a dotted line around it. When I press the down arrow on my keyboard I should expect item4 to be selected. But instead item2 is selected as though I have pressed the up arrow. This must mean that item1 is the selected item when the form loads. Can anyone help me to solve this problem please? Lucy

    C# help database question

  • Selecting an item in a checked listview when form loads
    L Lucy

    Thank you for your help. Yes I noticed that both of these events were fired many times whilst debugging. I now understand a bit more about stacks. I will try and use boolean values to solve my problem. Lucy

    C# help database question

  • Selecting an item in a checked listview when form loads
    L Lucy

    It is a listview with checkboxes. Lucy

    C# help database question

  • Selecting an item in a checked listview when form loads
    L Lucy

    So the SelectIndexChanged event would fire when the user selects an item? How would I do that? Lucy

    C# help database question

  • Selecting an item in a checked listview when form loads
    L Lucy

    I have a checked listview on my windows form. When the form loads I have code where a specific item in the listview is selected: listView1.Items[1].Selected = true; But I also have a selected index changed event. In this event I go through all listview items and set their checked property to false and then check the item that has just been selected: foreach (ListViewItem lvi in listView1.Items) { lvi.Checked = false; } listView1.SelectedItems[0].Checked = true; These two pieces of code do not work together. If I comment one section of code, then no errors occur and vis versa but when both pieces of code are not commented out I get the following error at run time: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll How do I solve my problem as both pieces of code are needed. Lucy

    C# help database question

  • Error when adding a ToolStripMenuItem [modified]
    L Lucy

    No none of my files are read-only. Lucy

    C# help debugging question csharp database

  • Error when adding a ToolStripMenuItem [modified]
    L Lucy

    I am using Visual Studio 2005. Yes I can add the menu item into the code easily and with no errors. Lucy

    C# help debugging question csharp database

  • Error when adding a ToolStripMenuItem [modified]
    L Lucy

    I am having trouble adding a ToolStripMenuItem but I do not know why. I have so far added many ToolStripMenuItems as follows: File New Save Save As Print Close Format Font Colour Help Contents Index Search About I want to add 3 more items under the Format menu, these being: Bold, Italic, Underlined. Each time I click on the drop down menu at design time and type Bold where it says 'Type Here' and then click away (This menu item with the text Bold should be saved) but the new menu item disappears as though I have not typed anything. When I try to type Bold again this error appears in a dialog box: The control System.Windows.Forms.TextBox has thrown an unhandled exception in the designer and has been disabled. Exception: Object reference not set to an instance of an object. Stack trace: I then get an error from Visual Studio saying: Microsoft Visual Studio has encounted a problem and needs to close. Also in this dialog box, there are 3 buttons, Debug, Send Error Report and Don't Send. Can anyone advise me as to what is going wrong when I try to add a ToolStripMenuItem? Lucy

    C# help debugging question csharp database

  • Help needed with a complicated application
    L Lucy

    Thank you! I will try that now. Lucy

    C# help question

  • Help needed with a complicated application
    L Lucy

    Sorry I am very new to C# and I am trying alter a console application example from a book to a windows form to test my skills and how much I have learnt. I think I haven't learnt to much and I have taken on a huge task. I have this method PlayGame() public void PlayGame() { Player[] players = new Player[1]; for (int p = 0; p < players.Length; p++) { string playerName = listBox1.SelectedItem.ToString(); players[p] = new Player(playerName); } if (players == null) return; for (int p = 0; p < players.Length; p++) { for (int c = 0; c < 7; c++) { players[p].PlayHand.Add(playDeck.GetCard(currentCard++)); } } //int currentPlayer; Card playCard = playDeck.GetCard(currentCard++); discardedCards.Add(playCard); for (currentPlayer = 0; currentPlayer < players.Length; currentPlayer++) { label1.Text = players[currentPlayer].Name + "'s turn."; labelHiden.Text = Convert.ToString(currentPlayer); label2hiden.Text = Convert.ToString(players[currentPlayer]); foreach (Card card in players[currentPlayer].PlayHand) { listBox2.Items.Add(Convert.ToString(card)); //richTextBox1.Text = Convert.ToString(card); } label3.Text = "Card in play: " + playCard; if (discardedCards.Contains(playCard)) { discardedCards.Remove(playCard); } players[currentPlayer].PlayHand.Add(playCard); label1.Text = "Drawn: " + playCard; label1.Text = "New Hand:"; for (int i = 0; i < players[currentPlayer].PlayHand.Count; i++) { listBox2.Items.Add(i + 1 + ": " + players[currentPlayer].PlayHand[i]); //richTextBox1.Text = i + 1 + ": " + players[currentPlayer].PlayHand[i]; } label3.Text = "Choose card to discard:"; } current = playCard; //return; } I only want this section of code to execute if a button is clicked: if (discardedCards.Contains(playCard))

    C# help question

  • Help needed with a complicated application
    L Lucy

    Is there a way of calling a method but not calling the first line of the method? I have a generic List called PlayHand. I add to this list in the method PlayGame(). When the button is clicked I want to add a Card type to this list. But after the method PlayGame() has been called and the method has completed, the generic list PlayHand clears. Can anyone help? Im really stuck on this! Lucy

    C# help question

  • Getting REG_MULTI_SZ values into a listbox
    L Lucy

    I have tried changing ListBox2.Items.Add(key2.GetValue("MultiString2", items[i])); to ListBox2.Items.Add(key2.GetValue("MultiString2", items[i].ToString)); But the same problem occurs. All registry key and value names are correct. Stepping through the code I can see that the value for ListBox1.Items is {System.Windows.Forms.ListBox.ObjectCollection} Should the listbox items be an ObjectCollection? Lucy -- modified at 8:03 Friday 28th September, 2007

    C# windows-admin data-structures help question

  • Getting REG_MULTI_SZ values into a listbox
    L Lucy

    Hi I have 2 listboxes on my form and in the form load event I want to get values from specified registry keys to appear as items in to each listbox. The first listbox works fine using this code: RegistryKey key1 = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\RegKey_test"); if (key1.GetValue("MultiString1") != null) { ListBox1.Items.Clear(); string[] items = (string[])key1.GetValue("MultiString1"); for (int i = 0; i < items.Length; i++) { ListBox1.Items.Add(key1.GetValue("MultiString1", items[i])); } } But for the second listbox I have practically the exact same code (But with a different registry value name and listbox). However, when the form loads ListBox1 shows the correct values but ListBox2 shows 'String[]Array' for each number of multistring values. Here is my code for getting the values from "MultiString2" into ListBox2: RegistryKey key2 = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\RegKey_test"); if (key2.GetValue("MultiString2") != null) { ListBox2.Items.Clear(); string[] items = (string[])key2.GetValue("MultiString2"); for (int i = 0; i < items.Length; i++) { ListBox2.Items.Add(key2.GetValue("MultiString2", items[i])); } } Why do I have this error when both sections of code are not that different? Can anyone advise me please? Lucy

    C# windows-admin data-structures help question

  • Setting listbox items to the registry
    L Lucy

    Appologies if I sounded rude but I was not being rude at all. I am not very good at explaining things sometimes so I was genuinly asking if my description was confusing or not. Thanks for your comments I will try it out now. Lucy

    C# windows-admin help question

  • Setting listbox items to the registry
    L Lucy

    Yes I am getting an ArgumentException. I have a form with a listbox. When the form loads, each string in the multistring registry key is put into the listbox as an item. The user can then edit these items as well as removing and adding items. The items then need to be set as values back in the multistring registry key by the click of a button. Does that make sense?

    C# windows-admin help question

  • Setting listbox items to the registry
    L Lucy

    I didnt think that part was right. The error it returns is: The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted. If I just leave it as listBox1.Items the same error occurs.

    C# windows-admin help question

  • Setting listbox items to the registry
    L Lucy

    I have a listbox on a form that displays data from a registry key of value multistring. This listbox is filled when the form loads by this code: RegistryKey getItems = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\RegKey_test"); if (getItems.GetValue("Items") != null) { string[] itemName = (string[])getItems.GetValue("Items"); for (int i = 0; i < itemName.Length; i++) { listBox1.Items.Add(getItems.GetValue("Items", itemName)); } } This works fine. But when I want to set the listbox items to the registry with the following code, an error occurs: if (getItems.GetValue("Items") != null) { Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\RegKey_test", "Items", listBox1.Items.ToString(), RegistryValueKind.MultiString); } I no that something is wrong with this line of code but I am not sure what it is. Can anyone advise me where I am going wrong please? Lucy

    C# windows-admin help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups