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
  1. Home
  2. General Programming
  3. C#
  4. TextBoxes, ListView, DataGrid or something else?

TextBoxes, ListView, DataGrid or something else?

Scheduled Pinned Locked Moved C#
questioncsharpdatabasevisual-studiowindows-admin
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheBlindWatchmaker
    wrote on last edited by
    #1

    Hi all, I am working on a an application that needs to do the following: 1. Query the registry for all the keys (approx. 100) that are written by another application and 2. Displays this information on a form. 3. Write this information to a log file. I am using Visual Studio .NET 2010 on a Win 7 machine. The limitation I have to work with is that I have to use the .NET 3.5 framework since that is what is installed with Win 7. I have steps 1 and 3 figured out but I have a question about step 2. What control(s) should I use to display this information? The display itself can be very simple, for example: REGISTRY KEY VALUE KEY 1 0 KEY 2 20 KEY 3 0x3FF ... NOTE: The Key names will be populated in advance by the application. The Values will be populated upon each query. Should I use several TextBoxes? This appears to be the brute force method and not very scalable. I tried playing with a ListView but it doesn't seem like I can update only the "Value" column. What would you suggest?

    M B 2 Replies Last reply
    0
    • T TheBlindWatchmaker

      Hi all, I am working on a an application that needs to do the following: 1. Query the registry for all the keys (approx. 100) that are written by another application and 2. Displays this information on a form. 3. Write this information to a log file. I am using Visual Studio .NET 2010 on a Win 7 machine. The limitation I have to work with is that I have to use the .NET 3.5 framework since that is what is installed with Win 7. I have steps 1 and 3 figured out but I have a question about step 2. What control(s) should I use to display this information? The display itself can be very simple, for example: REGISTRY KEY VALUE KEY 1 0 KEY 2 20 KEY 3 0x3FF ... NOTE: The Key names will be populated in advance by the application. The Values will be populated upon each query. Should I use several TextBoxes? This appears to be the brute force method and not very scalable. I tried playing with a ListView but it doesn't seem like I can update only the "Value" column. What would you suggest?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Presumably your data container is a List where regkey has 2 fields Key and Value. Then bind that list as the datasource for the datagridview.

      Never underestimate the power of human stupidity RAH

      T 1 Reply Last reply
      0
      • M Mycroft Holmes

        Presumably your data container is a List where regkey has 2 fields Key and Value. Then bind that list as the datasource for the datagridview.

        Never underestimate the power of human stupidity RAH

        T Offline
        T Offline
        TheBlindWatchmaker
        wrote on last edited by
        #3

        Thanks, Mycroft. I could create a list of registry key names and bind that list as the datasource to the datagridview. However, when the application runs, it will have to query the registry for each of those key names and then display the values of the key in the second column. To clarify, when the application is first opened, I will have: NAME VALUE Key1 (blank) Key2 (blank) Key3 (blank) ... When I click on "Run", I want to see NAME VALUE Key1 Value1 Key2 Value2 Key3 Value3 ... Should I then put Key1, Key2, Key3, etc... in a List? Thanks!

        M W 2 Replies Last reply
        0
        • T TheBlindWatchmaker

          Thanks, Mycroft. I could create a list of registry key names and bind that list as the datasource to the datagridview. However, when the application runs, it will have to query the registry for each of those key names and then display the values of the key in the second column. To clarify, when the application is first opened, I will have: NAME VALUE Key1 (blank) Key2 (blank) Key3 (blank) ... When I click on "Run", I want to see NAME VALUE Key1 Value1 Key2 Value2 Key3 Value3 ... Should I then put Key1, Key2, Key3, etc... in a List? Thanks!

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Try it, you'll find that when your app runs it should get the value from the registry, locate the record in then List<> based on the key and add the value to the field. The DGV will automatically reflect the new data in the List<>. Once you have created the List<> and bound it to the DGV you can ignore the DGV and work with the underlying data container - the List<>

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • T TheBlindWatchmaker

            Thanks, Mycroft. I could create a list of registry key names and bind that list as the datasource to the datagridview. However, when the application runs, it will have to query the registry for each of those key names and then display the values of the key in the second column. To clarify, when the application is first opened, I will have: NAME VALUE Key1 (blank) Key2 (blank) Key3 (blank) ... When I click on "Run", I want to see NAME VALUE Key1 Value1 Key2 Value2 Key3 Value3 ... Should I then put Key1, Key2, Key3, etc... in a List? Thanks!

            W Offline
            W Offline
            Wayne Gaylard
            wrote on last edited by
            #5

            Why don't you use a Dictionary. Then when the form opens you can populate each key of the KeyValuePair, bind the DGV to the Dictionary, then you can populate each value as and when you need to, or it becomes available, and rebind the DGV. Just a thought :) ...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....

            T 1 Reply Last reply
            0
            • T TheBlindWatchmaker

              Hi all, I am working on a an application that needs to do the following: 1. Query the registry for all the keys (approx. 100) that are written by another application and 2. Displays this information on a form. 3. Write this information to a log file. I am using Visual Studio .NET 2010 on a Win 7 machine. The limitation I have to work with is that I have to use the .NET 3.5 framework since that is what is installed with Win 7. I have steps 1 and 3 figured out but I have a question about step 2. What control(s) should I use to display this information? The display itself can be very simple, for example: REGISTRY KEY VALUE KEY 1 0 KEY 2 20 KEY 3 0x3FF ... NOTE: The Key names will be populated in advance by the application. The Values will be populated upon each query. Should I use several TextBoxes? This appears to be the brute force method and not very scalable. I tried playing with a ListView but it doesn't seem like I can update only the "Value" column. What would you suggest?

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              I would use a DataGridView, bound to a BindingList<RegistryEntry>, where

              class RegistryEntry {
              public string Key { get; private set; }
              public string Value { get; internal set; }
              }

              ... so the data binding only works off the (public) getters and therefore the grid is read-only. You can update extra columns in a ListView, though. Check out ListViewItem.Subitems[0][^]. A ListView in details mode or a DGV comes down to a personal preference for the appearance, for a task like this. (It is not possible to edit subitems of a list view though, so if you want the user to be able to modify values before logging then a DGV is the way to go.)

              1 Reply Last reply
              0
              • W Wayne Gaylard

                Why don't you use a Dictionary. Then when the form opens you can populate each key of the KeyValuePair, bind the DGV to the Dictionary, then you can populate each value as and when you need to, or it becomes available, and rebind the DGV. Just a thought :) ...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....

                T Offline
                T Offline
                TheBlindWatchmaker
                wrote on last edited by
                #7

                Thanks Mycroft, Wayne and Bob for your very helpful replies. So, I have this now: // In Form1.Designer.cs private System.Windows.Forms.DataGridView dgv_static_keys; // In Form1.cs Dictionary<string, string> dict_static_keys = new Dictionary<string, string> { {"Key1", "Value1"}, {"Key2", "Value2"}, {"Key3", "Value3"}, }; BindingSource bindingsource = new BindingSource(); bindingsource .DataSource = dict_static_keys; dgv_static_keys.DataSource = bindingsource; If I were to now update the Dictionary with a new key, say dict_static_keys.Add("Key4", "Value4"); How do I get the DataGridView to update? I tried this dg_static_keys.DataSource = dict_static_keys.ToList(); but is there a better solution?

                B 1 Reply Last reply
                0
                • T TheBlindWatchmaker

                  Thanks Mycroft, Wayne and Bob for your very helpful replies. So, I have this now: // In Form1.Designer.cs private System.Windows.Forms.DataGridView dgv_static_keys; // In Form1.cs Dictionary<string, string> dict_static_keys = new Dictionary<string, string> { {"Key1", "Value1"}, {"Key2", "Value2"}, {"Key3", "Value3"}, }; BindingSource bindingsource = new BindingSource(); bindingsource .DataSource = dict_static_keys; dgv_static_keys.DataSource = bindingsource; If I were to now update the Dictionary with a new key, say dict_static_keys.Add("Key4", "Value4"); How do I get the DataGridView to update? I tried this dg_static_keys.DataSource = dict_static_keys.ToList(); but is there a better solution?

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #8

                  That's why I suggested using a BindingList, because it updates BindingSources that are hooked to it when the list is changed. It looks like BindingSource.ResetBindings is a slightly less brute force way to refreshing the binding if you don't want to use BindingList.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

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