I post a bit of the code here...
I post part of the DataList and DataMapping I am using in my example in case the problem lies here.
I have several int's double strings etc in my code to make it general. But here I have removed them to make the code shorter.
public class DataList
{
private string myString1 = "";
private int myInt1 = 0;
private bool isNullInt1 = true;
public DataList()
{
}
public string string1
{
get {return myString1;}
set {myString1 = value;}
}
public int int1
{
get {return myInt1;}
set {myInt1 = value;isNullInt1 = false;}
}
public bool isNullint1
{
get {return isNullInt1;}
}
}
}
//-----------------------------------------------------------
public class DataMapping
{
private StringCollection myMappingName;
private StringCollection myMappingTable;
private StringCollection myMappingColumn;
private StringCollection myInternalName;
private StringCollection myRelationName;
private StringCollection myType;
private ArrayList myIndex; private ArrayList dataLists;
private int intUsed = 0;
private int stringUsed = 0;
private int myCount = 0;
public ArrayList arrayList
{
get
{
return dataLists;
}
}
public void clearDataList()
{
dataLists.Clear();
}
public DataMapping()
{
this.dataLists = new ArrayList();
this.myMappingName = new StringCollection();
this.myMappingTable = new StringCollection();
this.myMappingColumn = new StringCollection();
this.myInternalName = new StringCollection();
this.myRelationName = new StringCollection();
this.myType = new StringCollection();
this.myIndex = new ArrayList();
}
public int getNRelations()
{
return this.myRelationName.Count;
}
public string getRelationName(int item)
{
return this.myRelationName[item];
}
public string getTableName(int item)
{
return this.myMappingTable[item];
}
public void Add(string mappingName,string mappingTable,string mappingColumn,string type,string relationName)
{
addMapping(mappingName,mappingTable,mappingColumn,type);
this.myRelationName.Add(relationName);
}
// mappingName a unique name for this mapping
// mappingTable table to find the value
// mappingColumn column in mappingTable to find value
// type int or string (so far)
public void Add(string mappingName,string mappingTable,string mappingColumn,string type)
{
addMapping(mappingName,mappingTable,mappingColumn,type);
this.myRelationName.Add("");
}
private void addMapping(string mappingName,string mappingTable,string mappingColumn,string type)
{
this.myCount++;
this.myMappingName.Add(mappingName);
this.myMappingTable.Add(mappingTable);
this.myMappingColumn.Add(mappingColumn);
this.myType.Add(type);
// ie: we have "round" as the first mappingname and it is an int
string internalName = "";
int index = 0;
switch(type)
{
case "int":
intUsed++;
index = intUsed;
internalName = "int"+intUsed;
break;
case "string":
stringUsed++;
index = stringUsed;
internalName = "string"+stringUsed;
break;
}
this.myInternalName.Add(internalName);
this.myIndex.Add(index);
}
public string getInternalName(string mappingName)
{ // returns the internal name corresponding the mappingName
int item = this.myMappingName.IndexOf(mappingName);
return this.myInternalName[item];
}
public string getMappingNameFromColumnName(string columnName)
{
int item = this.myMappingColumn.IndexOf(columnName);
return this.myMappingName[item];
}
public string getColumnName(int item)
{
return this.myMappingColumn[item];
}
public string getInternal(int item)
{
return this.myInternalName[item];
}
public string getMapping(int item)
{
return this.myMappingName[item];
}
public string getType(int item)
{
return this.myType[item];
}
public int getIndex(string mappingName)
{
int item = this.myMappingName.IndexOf(mappingName);
int index = 0;
index = (int)this.myIndex[item];
return index;
}
public void AddDataList()
{
dataLists.Add(new DataList());
}
public void setValue(int row,string mappingName,int intValue)
{
switch(getIndex(mappingName))
{
case 1:
((DataList)dataLists[row]).int1 = intValue;
break;
}
}
public void setValue(int row,string mappingName,string stringValue)
{
switch(getIndex(mappingName))
{
case 1:
((DataList)dataLists[row]).string1 = stringValue;
break;
}
}
public int getIntValue(int row,string mappingName)
{
switch(getIndex(mappingName))
{
case 1:
return ((DataList)dataLists[row]).int1;
}
return 0;
}
public bool getIsNullInt(int row,string mappingName)
{
switch(getIndex(mappingName))
{
case 1:
return ((DataList)dataLists[row]).isNullint1;
}
return true;
}
public string getStringValue(int row,string mappingName)
{
switch(getIndex(mappingName))
{
case 1:
return ((DataList)dataLists[row]).string1;
}
return "";
}
public int Count
{
get {return myCount;}
}
}
}
//-----------------------------------------------------------
Code for columnstyles
public void addDataMapping(string mappingName,string mappingTable,string mappingColumn,string type)
{
dataManager.addDataMapping(mappingName,mappingTable,mappingColumn,type);
}
public void addDataMapping(string mappingName,string mappingTable,string mappingColumn,string type,string relationName)
{
dataManager.addDataMapping(mappingName,mappingTable,mappingColumn,type,relationName);
}
public string getDataInternalName(string mappingName)
{
return dataManager.getDataInternalName(mappingName);
}
public void addDataGridTableStyle(DataGrid dataGrid)
{
gridTableStyle = new DataGridTableStyle();
gridTableStyle.DataGrid = dataGrid;
gridTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText;
// if using dataMappings we have an ArrayList inside the DataMapping object
// and mappingName must be "ArrayList"
// otherwise mappingName is the name of tables[0]
// since we then should only have one table
if(this.getDataMapping().Count > 0)
gridTableStyle.MappingName = "ArrayList";
else
gridTableStyle.MappingName = getDataSet().Tables[0].TableName;
dataGrid.TableStyles.Add(gridTableStyle);
}
public void addGridColumnStyle(string header,string mappingName,int width,bool readOnly,string columnType,string formatString)
{
DataGridTextBoxColumn column = new DataGridTextBoxColumn();
column.HeaderText = header;
// check if we have dataMappings
if(this.getDataMapping().Count > 0)
column.MappingName = getDataInternalName(mappingName); // the the internal mapping name
else
column.MappingName = mappingName; // mapping name is the name itself
column.Width = width;
column.ReadOnly = readOnly;
column.TextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyDown);
column.TextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.KeyUp);
if(!formatString.Equals(""))
column.Format = formatString;
gridTableStyle.GridColumnStyles.Add(column);
}
//-----------------------------------------------------------
Code to setup my datamapping and columnstyles for my datagrid
addDataMapping("bedid","bed","bedid","int");
addDataMapping("roomid","bed","roomid","int");
addDataMapping("bedname","bed","bedname","string");
...
addDataGridTableStyle(this.grid);
addGridColumnStyle("BedId","bedid",0,false,"TextBox","");
addGridColumnStyle("RoomId","roomid",0,false,"TextBox","");
addGridColumnStyle("Bed Name","bedname",80,false,"TextBox","");