khyberman
asked on
DataGridView in C#
How can I change the Row Label in column 0 (the left most column) in a DataGridView. I am able to change all columns in a new row but the left most because it doesn't seem to have a label. Here is a code snippet of what I got so far: Thx
public static DataTable Get()
{
DataTable table = new DataTable("tablePQ");
DataColumn Coldt;
DataRow Rowdt;
foreach (string label in Enum.GetNames(typeof(Table LabelsPQ)) )
{
Coldt = new DataColumn();
Coldt.DataType = System.Type.GetType("Syste m.String") ;
Coldt.ColumnName = label;
Coldt.AutoIncrement = false;
Coldt.Caption = label;
Coldt.ReadOnly = false;
Coldt.Unique = true;
table.Columns.Add(Coldt);
foreach (string inst in Enum.GetNames(typeof(Curre ncies)))
{
Rowdt = table.NewRow();
Rowdt["Symbol"] = inst;
table.Rows.Add(Rowdt);
}
}
return table;
}
public static DataTable Get()
{
DataTable table = new DataTable("tablePQ");
DataColumn Coldt;
DataRow Rowdt;
foreach (string label in Enum.GetNames(typeof(Table
{
Coldt = new DataColumn();
Coldt.DataType = System.Type.GetType("Syste
Coldt.ColumnName = label;
Coldt.AutoIncrement = false;
Coldt.Caption = label;
Coldt.ReadOnly = false;
Coldt.Unique = true;
table.Columns.Add(Coldt);
foreach (string inst in Enum.GetNames(typeof(Curre
{
Rowdt = table.NewRow();
Rowdt["Symbol"] = inst;
table.Rows.Add(Rowdt);
}
}
return table;
}
ASKER
Sorry the code was incorrect. The below is the correct version. I am trying to assign a value to the left most column in the row (which is colored grey), I am not abkle to do that through column labels. Thx
public static DataTable Get()
{
DataTable table = new DataTable("tablePQ");
DataColumn Coldt;
DataRow Rowdt;
foreach (string label in Enum.GetNames(typeof(Table LabelsPQ)) )
{
Coldt = new DataColumn();
Coldt.DataType = System.Type.GetType("Syste m.String") ;
Coldt.ColumnName = label;
Coldt.AutoIncrement = false;
Coldt.Caption = label;
Coldt.ReadOnly = false;
Coldt.Unique = true;
table.Columns.Add(Coldt);
}
foreach (string inst in Enum.GetNames(typeof(Curre ncies)))
{
Rowdt = table.NewRow();
Rowdt["Symbol"] = inst;
table.Rows.Add(Rowdt);
}
return table;
}
public static DataTable Get()
{
DataTable table = new DataTable("tablePQ");
DataColumn Coldt;
DataRow Rowdt;
foreach (string label in Enum.GetNames(typeof(Table
{
Coldt = new DataColumn();
Coldt.DataType = System.Type.GetType("Syste
Coldt.ColumnName = label;
Coldt.AutoIncrement = false;
Coldt.Caption = label;
Coldt.ReadOnly = false;
Coldt.Unique = true;
table.Columns.Add(Coldt);
}
foreach (string inst in Enum.GetNames(typeof(Curre
{
Rowdt = table.NewRow();
Rowdt["Symbol"] = inst;
table.Rows.Add(Rowdt);
}
return table;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your code, you have a the loop for creating a datatable row within the loop for creating the columns.