Skip to content

C# databinding / relation

Bas van Berkel

Asked May 20, 2008, 12:51 AM EDT1 answer
Share
LinkedInX

Hi all,

I have a question about my c# windows application.
I have 2 datatables:
- myUserDataTable
- myCountriesDataTable

Now I want to add a textboxcolumn in my datagridview.

In myUserDataTable there is a column with prefix of countrynames. f.e. GB / NL / USA etc.
In myCountriesDataTable I have 2 columns. 1 columns with the prefixxes, and one with the full name of the country.
Now I want to display the fullnames of the country in my textbox.

F.e:
User 1 has preferred team : GB.
Now I must do a search or a relationship must be created to look up the full name of that country

Can somebody help?



1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    OK,

    Solved it already.
    Didn't do it with a textboxcolumn, but with a comboboxcolumn:

    Code
    DataGridViewComboBoxColumn countryComboBoxColumn = new DataGridViewComboBoxColumn();
    countryComboBoxColumn.DataSource = myCountryDataTable;
    countryComboBoxColumn.DisplayMember = myCountryDataTable.CountryNameColumn.ColumnName;
    countryComboBoxColumn.ValueMember = myCountryDataTable.CountryCodeColumn.ColumnName;
    countryComboBoxColumn.DataPropertyName = myUserDataTable.CountryCodeColumn.ColumnName;
    countryComboBoxColumn.HeaderText = myCountryDataTable.CountryNameColumn.ColumnName;
    countryComboBoxColumn.Name = myCountryDataTable.CountryNameColumn.ColumnName;
    countryComboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;

     

    perfectly :-)

    0