현재 데이터베이스 프로젝트에서 작업하고 있지만 GUI가 올바르게 업데이트되지 않습니다.DataGridView가 올바르게 업데이트되지 않습니다.
내 프로그램에는 현재 네 개의 DataGridView가 있습니다. 첫 번째 밴드는 모든 밴드를 포함합니다. 두 번째는 선택된 밴드의 모든 밴드 멤버를 보여줍니다. 세 번째 밴드는 선택한 밴드의 모든 앨범을 보여줍니다. 네 번째 앨범은 선택한 앨범의 모든 트랙을 보여줍니다.
두 밴드 사이를 전환하면 밴드 멤버와 앨범이 잘 업데이트됩니다. 여기에 문제가 있습니다 :
두 개의 밴드가 있습니다. 첫 번째 테이블에는 이미 두 개의 항목이 있습니다. 둘째 밴드에만 있습니다.
그래서 밴드 1에서 밴드 2로 전환하면 트랙 DataGridView가 올바르게 업데이트되지 않고 첫 번째 앨범의 트랙이 계속 표시됩니다. 내가 말했듯이 나머지는 잘 업데이트됩니다. 여기
내 코드입니다 :public partial class Form1 : Form
{
MusicDB Context = new MusicDB();
BindingSource bsSourceAlbum = new BindingSource();
BindingSource bsSourceMember = new BindingSource();
BindingSource bsSourceTrack = new BindingSource();
public Form1()
{
InitializeComponent();
this.AlbumDataGridView.AutoGenerateColumns = false;
this.MemberDataGridView.AutoGenerateColumns = false;
this.TrackDataGridView.AutoGenerateColumns = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Context.cInterpret.Load();
BindingSource bsSourceInterpret = new BindingSource();
bsSourceInterpret.DataSource = Context.cInterpret.Local;
InterpretDataGridView.DataSource = bsSourceInterpret;
InterpretDataGridView.Columns[0].Visible = false;
InterpretDataGridView.Columns[3].Visible = false;
InterpretDataGridView.Columns[4].Visible = false;
InterpretDataGridView.Columns["InterpretName"].HeaderText = "Interpret";
InterpretDataGridView.Columns["InterpretFounding"].HeaderText = "Gründungsjahr";
bsSourceInterpret.AllowNew = true;
Context.cLabel.Load();
AlbumLabelColumn.DataSource = Context.cLabel.Local;
AlbumLabelColumn.DisplayMember = "LabelName";
AlbumLabelColumn.ValueType = typeof(MusicLabel);
AlbumLabelColumn.ValueMember = "Self";
Context.cGenre.Load();
AlbumGenreColumn.DataSource = Context.cGenre.Local;
AlbumGenreColumn.DisplayMember = "GenreName";
AlbumGenreColumn.ValueType = typeof(Genre);
AlbumGenreColumn.ValueMember = "Self";
Context.cInstrument.Load();
MemberInstrumentColumn.DataSource = Context.cInstrument.Local;
MemberInstrumentColumn.DisplayMember = "InstrumentName";
MemberInstrumentColumn.ValueMember = "InstrumentID";
MemberInstrumentColumn.ValueType = typeof(Instrument);
MemberInstrumentColumn.ValueMember = "Self";
bsSourceTrack.AllowNew = true;
bsSourceAlbum.AllowNew = true;
bsSourceMember.AllowNew = true;
AlbumDataGridView.DataSource = bsSourceAlbum;
MemberDataGridView.DataSource = bsSourceMember;
TrackDataGridView.DataSource = bsSourceTrack;
}
private void InterpretDataGridView_SelectionChanged_1(object sender, EventArgs e)
{
//bsSourceMember.Clear();
//bsSourceAlbum.Clear();
DataGridView SenderGridView = (DataGridView)sender;
if (SenderGridView.CurrentRow != null && SenderGridView.CurrentRow.DataBoundItem != null && SenderGridView.CurrentRow.DataBoundItem is Interpret)
{
bsSourceAlbum.DataSource = ((Interpret)((DataGridView)sender).CurrentRow.DataBoundItem).Albums;
bsSourceMember.DataSource = ((Interpret)((DataGridView)sender).CurrentRow.DataBoundItem).Members;
}
}
private void AlbumDataGridView_SelectionChanged(object sender, EventArgs e)
{
bsSourceTrack.Clear();
DataGridView SenderGridView = (DataGridView)sender;
if (SenderGridView.CurrentRow != null && SenderGridView.CurrentRow.DataBoundItem != null && SenderGridView.CurrentRow.DataBoundItem is Album)
{
bsSourceTrack.DataSource = ((Album)((DataGridView)sender).CurrentRow.DataBoundItem).Tracks;
}
}
}
당신은 시도'InterpretDataGridView.Update()'또는'InterpretDataGridView.UpdateCellValue (I, J)'이미? – Essigwurst
예. 작동하지 않습니다. – Raphnika