mardi 21 avril 2015

Combobox added to datagridview losses its selection

I am trying to populate a datagrid table and add an additional combobox in a Winforms application to allow the user to select from an exception list.

The datagrid is populated using a Stored Procedure on SQL server. (NOTE: due to my ITs security I have to go through a single server using linked servers to where the data is to query the data so the stored procedure uses dynamic SQL)

The data pulls properly and the additional combobox appears however once I select an exception on 1 row and try to go to the next row, the first combobox's selection disappears.

An additional question, given the nature or how I query the data, how would I update the data on the original sql tables from datagrid? Another stored procedure?

FYI, I'm a SQL developer but I'm fairly new to C#

My code is below for the datagridview method. Thanks in advance.

    public void displayDataGridView(string param)
    {
        SqlConnection con = new SqlConnection("Data Source = SQLServer1; initial catalog=GlbDBNames; integrated security=true ");

        {   
            SqlCommand cmd;
            cmd = new SqlCommand(param, con);
            cmd.CommandTimeout = 60 * 20;
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dg_batchsummary.DataSource = ds.Tables[0];
            dg_batchsummary.Columns[0].Width = 200;
            dg_batchsummary.AutoGenerateColumns = false;
            dg_batchsummary.AllowUserToAddRows = false;


             DataGridViewComboBoxColumn ExceptionList = new DataGridViewComboBoxColumn();
             ExcptionList.HeaderText = "Exception List";
             ExceptionList.Name = "Newexcept";
             ExceptionList.Items.AddRange("Item1","Item2","Item3");

             dg_batchsummary.Columns.Add(ExceptionList);
        }

Aucun commentaire:

Enregistrer un commentaire