TextBoxes, ListView, DataGrid or something else?
-
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?
-
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?
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
-
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
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!
-
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!
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
-
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!
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.....
-
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?
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.)
-
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.....
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, saydict_static_keys.Add("Key4", "Value4");
How do I get the DataGridView to update? I tried thisdg_static_keys.DataSource = dict_static_keys.ToList();
but is there a better solution? -
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, saydict_static_keys.Add("Key4", "Value4");
How do I get the DataGridView to update? I tried thisdg_static_keys.DataSource = dict_static_keys.ToList();
but is there a better solution?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.