Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to set DataSource and DataBindings in Combobox which is in DataGridView

$
0
0

Hi  everyone

I have one problem about this

In win form application I have two comboboxes which one is  dragged in win form directly and second is in column in DataGridView. In Database I have two tables Articles and Purchase. I need to choose some item from combobox which is bound from source table and save this item in destination table. For first combobox it is not problem, I wrote

List<string> items =newList<string>();

           conn = newOracleConnection(connectionString);

           conn.Open();

           commandString = "SELECT NAME_OF_ARTICLES FROM ARTICLES ";

           cmd = newOracleCommand(commandString, conn);

           OracleDataReader reader =  cmd.ExecuteReader();

 

           if (reader.HasRows)

           {

               while (reader.Read())

               {

                   string name = reader.GetString(0);

                    items.Add(name);

                                   }

                Combobox1.DataSource = items;

           }

           conn.Close();

 

When I choose one item from combobox1 then I need to save this item in destionation table named Purchase in database like this: I use BindingNavigator from toolbox and I set Property BindingSource on PurchaseBindingSource which is also dragged from toolbox. In Combobox1 for Property (DataBindings) I set Text on PurchaseBindingsource, so I use BindingNavigator to save data on button Save in it andnavigate through data in datatable using  next and previous button. The Problem is in the second combobox in which is in DataGridView where don’t  existe Property (DataBindings) only have DataSource. I did: in DataGridView I opened DataGridView Tasks and clicked edit column. Column named Article I set: DataPropertyName on Article, DataSource on articleBindingSource, DisplayMember Article and HeaderText on Article, and then the combobox is filled with data, when I can choose some data, but how I can bind it with BindingNavigator, acctualy PurchaseBindingSource like first because don’t existe (DataBounds) and then navigate through records. For DataGridView in Edit Columns in Data I did not find (DataBounds) only DataSource.

Or like this in code instead of wizard

DataGridViewComboBoxColumn columnArticle =this.dataGridViewOrder.Columns[1] asDataGridViewComboBoxColumn;//it is position on my combobox

         

           

           string selectQueryString = "SELECT NAME_OF_ARTICLES FROM ARTICLES";

           OracleDataAdapter oracleDataAdapter = newOracleDataAdapter(selectQueryString, conn);

           OracleCommandBuilder oracleCommandBuilder =newOracleCommandBuilder(oracleDataAdapter);

           DataTable dataTable = newDataTable();

           oracleDataAdapter.Fill(dataTable);

           BindingSource bindingSource = newBindingSource();

           bindingSource.DataSource = dataTable;

 

 

           columnArticle.DataPropertyName = "Article";

            columnArticle.DataSource =articleBindingSource;

           columnArticle.DisplayMember = "Article";

            //columnArticle.DataBindings does not exist like first Combobox1.DataBindings

 

Please help me

thanks in advance


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>