Вопрос

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