I want to give a defined style of columns with their title and everything to a DataGrid, I present the records of a table called users where I use the following code made from C # with Visual Studio 2017
public void mostrarTabla()
{
String consulta = "select Nombre,ApellidoP,ApellidoM,Sexo,Telefono,Edad,Puesto from usuarios;";
SqlDataAdapter dataAdapter = new SqlDataAdapter(consulta,new BaseDeDatos().obtenerConexion());
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridUsuarios.ItemsSource = ds.Tables[0].DefaultView;
}
It shows me the data well with the name of the correct columns, but everything looks very close together and aesthetically bad... and I can't find anything in the configuration provided by Visual Studio for the code on how to improve it
I will explain it to you by the way of interface.
First we create the
DataGrid
, after it there is a button in the upper right part (arrow type), when you click it a menu is displayed where you have the option to edit column :When clicking e, a new window will appear where you can create your columns:
You add as many columns as you need, once created you select one by one to give them a defined size with the width property.
For example, I gave him 120 for first and last name, 80 for sex and 70 for age.
You can do it with the Columns property like this:
And so with the rest of the columns, the collection of columns always starts at zero for the first
item
Cheers
I think what you need is to configure the table so that it automatically fills or adjusts to the title or content of the columns. In that order of ideas, perhaps this configuration will serve you.