делаю вывод данных из бд в datagridview но после вывода у меня все данные есть но они не видны в datagridview только при клике в ячейки появляется текст. Вот весь код
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace NetDevice
{
public partial class DevForm : Form
{
private SqlConnection db = null;
private SqlCommand cmd = new SqlCommand();
private SqlDataAdapter adapter = new SqlDataAdapter();
private DataTable dt = new DataTable();
public DevForm()
{
InitializeComponent();
}
private void DevForm_Load(object sender, EventArgs e)
{
db = new SqlConnection(ConfigurationManager.ConnectionStrings["Netdb"].ConnectionString);
show();
}
private void Res_dev_Click(object sender, EventArgs e)
{
this.txtId.Text = "";
this.txtName.Text = "";
this.txtManuf.Text = "";
this.txtAmount.Text = "";
}
private void Ins_dev_Click(object sender, EventArgs e)
{
if (this.txtName.Text == "")
{
MessageBox.Show("Please Enter a Name...");
}
if (this.txtManuf.Text == "")
{
MessageBox.Show("Please Enter a Manufacter...");
}
if (this.txtAmount.Text == "")
{
MessageBox.Show("Please Enter a Amount...");
}
else
{
string Name = txtName.Text;
string Manuf = txtManuf.Text;
string Amount = txtAmount.Text;
int amount = Int32.Parse(Amount);
db.Open();
string qry = "Insert into Devices (Name, Manufacter, Amount) values ('" + Name + "','" + Manuf + "','" + amount + "')";
cmd = new SqlCommand(qry, db);
if (cmd.ExecuteNonQuery() == 1)
{
MessageBox.Show("Device insert with Name: " + Name);
}
else
MessageBox.Show("Device inserted failed with Name: " + Name);
db.Close();
Res_dev_Click(sender, e);
}
}
void show()
{
adapter = new SqlDataAdapter("SELECT * FROM Devices", db);
dt = new DataTable();
adapter.Fill(dt);
Grid_Devices.Rows.Clear();
foreach (DataRow dr in dt.Rows)
{
int n = Grid_Devices.Rows.Add();
Grid_Devices.Rows[n].Cells[0].Value = dr[0].ToString();
Grid_Devices.Rows[n].Cells[1].Value = dr[1].ToString();
Grid_Devices.Rows[n].Cells[2].Value = dr[2].ToString();
Grid_Devices.Rows[n].Cells[3].Value = dr[3].ToString();
}
}
}
}
Вот фото как мне показывают все данные, хотя они должны быть видны изначально. Пожалуйста помогите, заранее спасибо
adapter.Fill(dt); Grid_Devices.DataSource = dt;