Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a scenario in which, i have MS SQL server databases a table name Items and another table name Item sizes and another table name size quantity means to say i have a product which has an item and each item has a size and each size has its own quantity,
while making invoice i want to have a grid view which will show me item list and user will select an item and insert in to next grid view there i have a combo box which will load sizes of the item and as u know each item has its own different sizes so i want to show them in each row differently so that User doesn't mix two product sizes
any urgent suggestion please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exemplary code will be very helpful....
<color>thanks best regards!!!!!!!!!
Posted

AS i got concerned with your question you have to add selected products in First column of

second gridview and and after that use Rowcreated or RowDataBound (or DataBound may also be used) Event of second grid view To load size and other corresponding data in a column next to First column of second gridview.
 
Share this answer
 
Comments
Salman khan mwi 13-Jun-14 10:43am    
I think you haven't got me correctly I will add a row and insert the item but as I said I want to see different sizes as e.g I have pent and pent has size 32 waste and 42 length, 33 WASTE 42 length and on other hand I have a shirt having size Small medium large or coller size 14, 15 16 17. So I want to show pent sizes in combo box of pent row and shirt size in combo box of shirt row so that's the problem
you can have a different dataSource for each row. I would suggest you to use DataTables - each of them will be for particular row (so combined they can be a set of DataSet).
One example (not using DataSet), but each row has its own dataSource:
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //column 1 (normal textColumn):
            dataGridView1.Columns.Add("col1", "Column1");
            //column 2 (comboBox):
            DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn();
            comboCol.Name = "cmbColumn";
            comboCol.HeaderText = "combobox column";
            dataGridView1.Columns.Add(comboCol);

            for (int i = 0; i < 10; i++)
            {
                string text = "item " + i;
                int[] data = { 1 * i, 2 * i, 3 * i };
                CreateCustomComboBoxDataSouce(i, text, data);
            }
        }

        private void CreateCustomComboBoxDataSouce(int row, string texst, int[] data) //row index        ,and two parameters
        {
            dataGridView1.Rows.Add(texst);
            DataGridViewComboBoxCell comboCell = dataGridView1[1, row] as  DataGridViewComboBoxCell;
            comboCell.DataSource = new BindingSource(data, null);
        }
    }


Another solution i have solve through using DataSet (multiple dataTables), and becuase DataSet is class variable, holds all the DataTables inside - and if you maybe need some values from a specifc dataTable, you can easily get it.

Example code:
C#
DataSet ds; //class variable
 public Form1()
 {
     InitializeComponent();

     ds = new DataSet();
     //column 1 (normal textColumn):
     dataGridView1.Columns.Add("col1", "Column1");
     //column 2 (comboBox):
     DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn();
     comboCol.Name = "cmbColumn";
     comboCol.HeaderText = "combobox column";
     dataGridView1.Columns.Add(comboCol);

     //using dataTable for each datasource:
     for (int i = 0; i < 10; i++)
     {
         string text = "item " + i; //data for text
         int[] data = { 1 * i, 2 * i, 3 * i }; //data for comboBox:

         //create new dataTable:
         DataTable table = new DataTable("table" + i);
         table.Columns.Add("column1", typeof(string));

         //fillig rows:
         foreach (int item in data)
             table.Rows.Add(item);

         //add table to dataSet:
         ds.Tables.Add(table);

         //creating new row in dgv (text and comboBox):
         CreateCustomComboBoxDataSouce(i, text, table);
     }
 }

 private void CreateCustomComboBoxDataSouce(int row, string texst, DataTable table) //row index ,and two parameters
 {
     dataGridView1.Rows.Add(texst);
     DataGridViewComboBoxCell comboCell = dataGridView1[1, row] as DataGridViewComboBoxCell;
     comboCell.DataSource = new BindingSource(table, null);
     comboCell.DisplayMember = "column1"; //name of column indataTable to display!!
     comboCell.ValueMember = "column1"; // vlaue if needed
     //(mostly you used these two propertes like: Name as DisplayMember, and Id as ValueMember)
 }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900