Hello, I'm hoping someone can help me out here. I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do. What I want to do is very simple: (1) I have a list of class instances thus: List<MyClass> classList = new List<MyClass>(); classList.Add(new MyClass("Fred")); classList.Add(new MyClass("Wilma")); etc
(2) I want each MyClass member of classList to be represented as a row in my DataGridView (3) I want to show only a subset of the class parameters, for example: public class MyClass { private string name; private string desc; private int anumber; // Want to show these in the interface public String Name { get { return (name); } set { name = value; } } public String Description { get { return (desc); } set { desc = value; } } // etc.. // I DON'T want to show this in the interface public int Number { get { return (anumber); } set { anumber= value; } } }
I understand that I need to set the DataSource parameter of my DataGridView to my data, in some way, but I don't seem to be able to get it to work. Do I need to do something to my classes to get it to work? I think that sums it up. No SQL, nothing just a nice list of data that I want to display. Can anyone help? Many thanks!! :)
JamesParsons
Posts
-
Simple example of DataGridView..? -
DataGridView : Getting startedMy formating didn't come out properly, the first line of code should read: List classList = new List(); classList.Add(new MyClass("Fred")); classList.Add(new MyClass("Wilma")); etc
-
DataGridView : Getting startedHello, I'm hoping someone can help me out here. I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do. What I want to do is very simple: (1) I have a list of class instances thus:
List classList;
(2) I want eachMyClass
member ofclassList
to be represented as a row in my DataGridView (3) I want to show only a subset of the class parameters, for example:public class MyClass { private string name; private int anumber; // Want to show this in the interface public String Name { get { return (name); } set { name = value; } } // I DON'T want to show this in the interface public int Number { get { return (anumber); } set { anumber= value; } } }
I think that sums it up. No SQL, nothing just a nice list of data that I want to display. Can anyone help? Many thanks!! -
Dockable Windows and Tabs like Visual StudioThanks, I'm giving that a go. Looks good!:-D
-
Adding Controls to UserControl / Component in VS DesignerHi, I'm trying to set up a UserControl or Component that consists of a label, which is colored and has Dock set to Top so that it spans the top of the UserControl/Component. Under this is a Panel, dock set to Fill. When I use this, I want controls that I add to it to be placed in the Panel. But I'm running into difficulties: When I try to do this by creating a UserControl, I cannot add Controls to an instance of it in the VS Designer. When I try to do this with a Component(inheriting from the Panel class), I can add to it, but the Controls end up in the top level Panel, not the inner panel. I could get around this by adding to it programatically, using a custom Add method, but I'd really like to be able to use the designer! Maybe the technique I'm using is incorrect? Or maybe I need to add some kind of override for my UserControl/Component's Add method? How do I do this? Thanks for any help you can offer me.
-
Dockable Windows and Tabs like Visual StudioHi, I'm developing an application that I would like to have the docking/tabbing functionality of the windows/panels, just like in Visual Studio. It doesn't appear to be part of the standard Toolbox controls - is it? Can someone point me in the right direction for information on adding this functionality into my application? Many thanks!
-
Reading data from Excel [modified]Thanks! That's great!!
-
Reading data from Excel [modified]Hello! I'm trying to read some data in from Excel. Now the spreadsheets that I'm accessing contain columns of data, and these columns may sometimes be blank, the main table might start a few columns in and so on. A raggedy old spreadsheet! In addition to this I don't know how many rows or columns there will be, so I need to be able to handle this. All the examples I've seen in the searches I've made have hard-coded limits. For example my table might look like this (can't quite format this right, but you'll get the idea):
DEPT.M LLD.OHMM MSFL.OHMM RHOB.G/CM3 NO SONIC IGLOO FISH# 1450 12.4303 2.279 2.3188 1450.25 12.4494 5.0599 2.3323 1450.5 14.7747 2.0675 2.2776 1450.75 14.768 1.2149 2.217 0.3974 1451 13.1767 0.4151 1451.25 16.8165 0.2921 0.3974 1451.5 29.4913 0.4151 1451.75 48.8114 0.2921 1452 44.7025 1452.25 28.3492 1452.5 19.2471 2.2749 2.1967 13.1371 0.3974 1452.75 13.4801 1.8502 2.232 13.3881 0.4151 1453 3.2926 2.3583 13.8325 0.2921 1453.25 3.6341 2.4099 1453.5 4.1754 2.356 102.0509 16.9615 10.3197 1453.75 16.9615 5.3556 2.3608 106.603 18.0078 10.7229 1454 18.0078 4.9902 2.3258 105.3982 17.1981 10.2939 1454.25 17.1981 4.6068 2.249 108.3167 16.2081 9.6294 1454.5 16.2081 3.389 2.2199 1454.75 15.7188 1.9904 2.1252 1455 18.0351 128.8776 1.7491 1455.25 28.9451 656.4312 1.4863 1455.5 43.2879 65.2774 1.6644 1455.75 31.8807 12.309 2.182 1456 18.3605 9.6465 2.3213 1456.25 19.039 7.1053 2.1123 1456.5 25.825 9.4629 1.6977
I have this kind of example below, but the limits are hard-coded. How can I get the correct limits so that I can read the whole sheet, regardless of it's size?
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); // this gets me a 10x10 block from my worksheet: for (int i = 1; i <= 10; i++) { Excel.Range range = worksheet.get_Range("A"+i.ToString(), "J" + i.ToString()); System.Array myvalues = (System.Array)range.Cells.Value2; // convert the output to something we can use.. string[] strArray = ConvertToStringArray(myvalues); ... etc }
But what I really want is (pseudo-code in CAPS):for (int i = 1; i <= worksheet.NUMBER_OF_ROWS; i++) { Excel.Range range = worksheet.get_Range(THE_WHOLE_ROW[i]); System.Array myvalues = (System.Array)range.Cells.Value2; string[] strArray = ConvertToStringArray(myvalues); ..