문제

I have a DataGridView that is bound to a BindingList<T> of a custom business object, with fields DeckID, Name, UserID, Size, and Notes.

This is being called up from an MSSQL database via an IDataReader object. Now, my problem is that UserID is an integer that, in my database, is a foreign key to a table called SystemUser, with a Username field.
What I want to do is grab the Username from the SystemUser table in my database, and display that, based on whatever UserID, display that name. This was all very easy in WebForms, using a GridView, but not so much on a WindowsForms app.

도움이 되었습니까?

해결책

I think I see what you are looking for. From the DataGridView instance get the selected item using an event like onSelectionChange. Next use:

var selectedItem = datagridviewinstance.SelectedRows[x].DataBoundItem as YourTypeHere
var data = (from a in SOMETHING where fk == selectedItem.ForeignKeyProperty select a);
textbox1.Text = data.text;

Now you can make your next database call to retrieve the foreign key object and update whatever GUI object you wish. Good luck!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top