0
데이터 그리드보기가 두 개 있습니다 (ValidationRun은 마스터이며 결과는 세부 사항입니다). 이 데이터를 포함하는 데이터 집합에 바인딩하는 중입니다. 디버깅 할 때 데이터를 볼 수 있습니다. 그러나 그리드에는 데이터가 없습니다.Datagridview에 데이터가 표시되지 않습니다.
아이디어가 있으십니까?
/class level objects
private DataGridView dgvValidationRun = new DataGridView();
private BindingSource bsValidationRun = new BindingSource();
private DataGridView dgvResults = new DataGridView();
private BindingSource bsResults = new BindingSource();
private void Form1_Load(object sender, EventArgs e)
{
// Bind the DataGridView controls to the BindingSource
// components and load the data from the database.
dgvValidationRun.DataSource = bsValidationRun;
dgvResults.DataSource = bsResults;
GetData();
// Resize the master DataGridView columns to fit the newly loaded data.
dgvValidationRun.AutoResizeColumns();
// Configure the details DataGridView so that its columns automatically
// adjust their widths when the data changes.
dgvResults.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
}
private void GetData()
{
try
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["XMLValidate.Properties.Settings.ValidationResultsConnectionString"].ConnectionString);
// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;
// Add data from the Customers table to the DataSet.
SqlDataAdapter daValidationRun = new SqlDataAdapter("select * from ValidationRun", connection);
daValidationRun.Fill(data, "ValidationRun");
// Add data from the Orders table to the DataSet.
SqlDataAdapter daResults = new SqlDataAdapter("select * from Result", connection);
daResults.Fill(data, "Result");
// Establish a relationship between the two tables.
DataRelation relRunResult = new DataRelation("RunResult",
data.Tables["ValidationRun"].Columns["RunId"],
data.Tables["Result"].Columns["RunId"]);
data.Relations.Add(relRunResult);
// Bind the run data connector to the Run table.
bsValidationRun.DataSource = data;
bsValidationRun.DataMember = "ValidationRun";
// Bind the results data connector to the results data connector,
// using the DataRelation name to filter the information in the
// details table based on the current row in the master table.
bsResults.DataSource = bsValidationRun;
bsResults.DataMember = "RunResult";
dgvValidationRun.AutoGenerateColumns = true;
dgvValidationRun.Refresh();
}
catch (Exception ex)
{
int i = 1;
}
}
은 양식 컨트롤에 dgvValidationRun이 추가 되었습니까? – nawfal
나는 아주 사소한 것으로 의심된다. catch를 제거하고 예외가 있는지 살펴 보자. – Steve
많은 분들이 nawfal에게 고마워했습니다. 그게 문제였습니다. 디자이너를 통해 양식에 추가 한 데이터 격자가 두 개 있지만 코드 숨김 - doh와 동일한 이름을 지정하는 것을 잊어 버렸습니다. –