0
I’m trying to add a column self-adjusting in a datagridview
but I am not able to figure out what is missing to work properly. My program reads the data from a database table and displays in a datagridview
. I need to add a column self-adjusting called 'Legend', because the table values are also represented in a graph and the column 'Legend' exists to facilitate the interpretation of the data by the user.
Follows part of the code responsible for this. The column called 'Caption' appears in datagridview
, but the lines are blank.
Conexao ca = new Conexao();
string sql = "";
sql += " Select ";
sql += " CausaDef, Incidencia ";
sql += " From ";
sql += " Relat ";
ca.Conectar();
OleDbDataAdapter da = new OleDbDataAdapter(sql, ca.cx);
DataSet ds = new DataSet();
da.Fill(ds, "DetGraf");
object sumObject;
sumObject = ds.Tables["DetGraf"].Compute("Sum(Incidencia)", "");
ds.Tables["DetGraf"].Rows.Add("TOTAL", sumObject.ToString());
DataColumn Legenda = new DataColumn();
Legenda.ColumnName = "Legenda";
Legenda.DataType = typeof(int);
Legenda.AutoIncrement = true;
Legenda.AutoIncrementSeed = 1;
Legenda.AutoIncrementStep = 1;
ds.Tables["DetGraf"].Columns.Add(Legenda);
dgvDetGraf.DataSource = ds.Tables["DetGraf"];
ca.Desconectar();
Put the total separate from the Main Grid and you cannot mix Caption with the data coming from the database. what you want to show put a picture of what you want to implement, I’ve seen two errors in your code I just won’t post an answer because I got more doubt kkk !
– user46523