0

I have a datagridview which is bind from a bindingsource I really try to find out how onclick row on datagridview the row data fill in the TextBox. Because I want to show some data on combobox according selection on datagridview. My code for bind the datagridview is below

private void FillGrid()
{
    if (_fisComp == null)
        _fisComp = new FiscalComponent();

    List<FiscalPeriod> _fisPeriod = _fisComp.GetAllByFiscalPeriod(Convert.ToString(fiscalYearComboBox.SelectedValue));

    fiscalPeriodBindingSource.DataSource = _fisPeriod;
    fiscalPeriodDataGridView.Refresh();
}

I am binding my datagridview by list<> type . The problem is that I am getting data from my stored procedure Y~N` and i want to display in combobox in Yes or No

This code is where I am binding my combobox

    public void FillDropdown()
    {

        var itemsleaverun = new BindingList<KeyValuePair<string, string>>();

            itemsleaverun.Add(new KeyValuePair<string, string>("Y", "Yes"));
            itemsleaverun.Add(new KeyValuePair<string, string>("N", "No"));
            leaveRunTypeComboBox.DataSource = itemsleaverun;
            leaveRunTypeComboBox.ValueMember = "Key";
            leaveRunTypeComboBox.DisplayMember = "Value";
            leaveRunTypeComboBox.SelectedIndex = 0;
     }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abhishek
  • 299
  • 2
  • 5
  • 18
  • What is your underlying `DataSource`? a `DataTable` or some collection of items which are type of some class having some `Properties`? You need to specify it more. Your problem is very simple. – King King Jun 11 '13 at 11:05
  • @KingKing i have edited my question please take a look – Abhishek Jun 11 '13 at 11:14
  • I want to mean your `DataGridView` DataSource, you want to bind one of it's DataSource members to a `TextBox`, so you have to know through that DataSource – King King Jun 11 '13 at 11:22
  • @KingKing my datagridview is directly bind from `fiscalPeriodBindingSource`. And i want to bind one value to `combobox`. Thanks – Abhishek Jun 11 '13 at 11:35
  • and yes I know but what is the underlying datasource of `fiscalPeriodBindingSource`? for example, if it's a `DataTable`, we will have `fiscalPeriodBindingSource = new BindingSource(yourDataTable,"");` and what member of that DataTable you want to bind to your combobox? – King King Jun 11 '13 at 11:54
  • Ah, I can see it is the `List` of `FiscalPeriod` so what about `FiscalPeriod`, what properties does it has? And which one do you want to bind to your combobox? – King King Jun 11 '13 at 12:01
  • @KingKing there are many properties on properties is `[DataMember] public int TaxMonth { get { return _taxMonth; } set { _taxMonth = value; NotifyPropertyChanged("TaxMonth"); } }` – Abhishek Jun 11 '13 at 12:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31581/discussion-between-abhishek-and-king-king) – Abhishek Jun 11 '13 at 12:05

1 Answers1

0

To bind one of the properties of FiscalPeriod to your combobox. I suppose you want to bind the Property X which can have values "Yes" or "No". You can bind it to your combobox like this:

yourComboBox.DataBindings.Add("Text", fiscalPeriodBindingSource, "X");

The Property X should be able to have values which are contained in the Items list of your comboBox. Because your combobox has a DataSource, they should be contained in the values list for the DataSource DisplayMember.

King King
  • 61,710
  • 16
  • 105
  • 130
  • in the Form constructor or Form load. The matter is the `fiscalPeriodBindingSource` and `yourComboBox` should be recognized as `declared` and your `fiscalPeriodBindingSource` should already be filled with data before. – King King Jun 11 '13 at 12:54