Sorry if I was too vague for you, I assumed if someone was familiar with
doing
what I was doing they would know what I was talking about.
the index is simply an integer like would be the index into the columns of a
DataGridView,
there is also a row index of course but thats easy its just a plain index
into an array.
the column index needs to refer to a title for the colum headers,
and to the particular data field of the class
the project is involved theres so much info i could give out
its hard to know where to draw the line.
I agree whole hartedly about reflection thats why I asked first,
having used it once before.
I have however come up with a solution wich solves my
worries about making absolutly sure the title/read/write all apply to the
same field.
the refererence is 100% certain the same for read/write,
and the title is on the same line so cant go too far wrong.
I havnt figured out how to actually do the write/set part yet
at least not with a function template.
public enum Get
{
Get,
Set,
Title
}
//does the actual get/set/title
public string GetSet<T>(string title, ref T field, string value, Get get)
{
if (get == Get.Title)
return title;
if (get == Get.Get)
return field.ToString();
if (get == Get.Set)
{
//need to come up with a way to read the text value in.
throw new Exception("The method or operation is not implemented.");
}
return null;
}
//looks up the relavant field/class data member
public override String FieldGet(int index, String value, Get get)
{
switch (index)
{
case 0: return FindIndex().ToString();
case 1: return GetSet("Org.X", ref surfProp.Origin.X, value, get);
case 2: return GetSet("Org.Y", ref surfProp.Origin.Y, value, get);
case 3: return GetSet("Org.Z", ref surfProp.Origin.Z, value, get);
default: return null;
}
}
//the actual data class
public class Surface //snipet of one of many much larger classes
{
public Vector3 Origin; //struct of 3 floats x,y,z
}
//the function wich fills in the datagrid rows and columns
public void FillGrid(DataGridView grid, List<Surface> surfaces)
{
int i;
String result;
grid.Columns.Clear(); ///assume surfaces isnt empty
for (i = 0; (result= surfaces[0].FieldGet(i, null, Get.Title)) != null;
i++)
grid.Columns.Add(result, result);
String[] row = new String[i];
grid.Rows.Clear();
foreach (Surface surf in surfaces)
{
for (i = 0; (result= surf.FieldGet(i, null, Get.Get)) != null; i++)
row[i]=result;
grid.Rows.Add(row);
}
}
this worked at least before I cut out the seemingly irrelavent stuff
>> [...]
>> so for each item I was thinking of having an array of strings wich
[quoted text clipped - 41 lines]
>
> Pete
Peter Duniho - 08 Dec 2007 20:05 GMT
> Sorry if I was too vague for you, I assumed if someone was familiar with
> doing
> what I was doing they would know what I was talking about.
Well, even if you assume that those of us who have replied to past threads
have perfect memory (and believe me, we don't), why restrict the pool of
potential answerers of this most recent question to those who have read
your previous questions?
If you want help, it makes no sense to do things that artificially
restrict the number of people who might answer the question. Just treat
each new question as a completely new topic. Make no assumptions about
what people might know from previous questions.
As far as the specific question goes, it seems to me that just as you
suggested at the end of your post, it's possible that data binding will
work for you here. I don't write much code myself that does data binding,
so I couldn't answer the specifics. But as near as I can tell, you really
just want to map data in your data structures to specific cells in a given
row of your DataGridView. As long as those data are exposed via a
property or some other binding-friendly mechanism (I think properties are
the easiest, but if I recall there are other ways), then you ought to be
able to bind your overall data to the table somehow.
Hopefully someone with more experience in data binding can fill in the
details for you. In the meantime, your time probably would not be wasted
if you spend some of it browsing the topics in MSDN related to data
binding.
Pete