I purchased Visual C# 2005 Step by Step on the hopes that it would help me learn how to use the DataGridView control among other things, but the instruction I looked at is very diluted. I've been sifting through the web and the help menu to help me learn this control for weeks. This is my latest issue I'm having trouble working through: I created a combobox columns for a DataGridView and I'm trying to code them so that one is dependent on the other to determine what values are available to select. For example, the first combobox shows a listing of Book Titles I get from a datatable. The other will show a listing of Authors I get from a different datatable. If a user selects a Book Title, I want the possible selections from the other combobox to refresh, limiting the choices only the the author that wrote the book. I've only been able to make this happen at the Column level. I need it to happen at the Cell level. This is what I've tried that re-populates the Author combobox cell for every row in the DataGridView, which is not what I want: private void dgCheckouts_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dgCheckouts.Columns["title"].Index) { dsAuthor = BookInv.dsGridAuthor(dgCheckouts[e.ColumnIndex, e.RowIndex].Value.ToString()); dtAuthor = dsAuthor.Tables[0]; cbcAuthor.DataSource = dtAuthor; cbcAuthor.DisplayMember = "author"; cbcAuthor.ValueMember = "author"; } } How can I get the cell to re-populate with only the Author that wrote the book (or Authors since that is technically if not remotely possible) on the
This is what I did to fix it for my situation: private void dgCheckouts_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dgCheckouts.Columns["title"].Index) { DataGridViewComboBoxCell lcbcAuthor = (DataGridViewComboBoxCell)dgCheckouts[dgCheckouts.Columns["author"].Index, e.RowIndex]; dsAuthor = BookInv.dsGridAuthor(dgCheckouts[e.ColumnIndex, e.RowIndex].Value.ToString()); dtAuthor = dsAuthor.Tables[0]; DataView ldvAuthor = new DataView(dtAuthor); bsc.DataSource = ldvAuthor; lcbcAuthor.DataSource = bsc; } }
Don't see what you're looking for? Try a search.
|