Hi,
I am new to .net windows application and I need a help.
I've taken a DataGridView in my windows application and there are 5 columns out of which one is dropdownlist from which I've to select a value and after selecting a value its subsequent data must be displayed in the same row i.e in the textbox.Also user can edit the data available in the textbox (of the remaining 4 columns).And, dynamically the next row must be created for the same purpose.
I am getting the values in dropdown list of first row and dynamically next row is also created but not getting the data filled in the textboxes, neither I'm getting values for the next row in the dropdown list, rather I'm getting an exception "Input string not in correct format."
Please check the following code private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
DataGridViewComboBoxColumn dgvComboBox;
DataGridViewTextBoxColumn dgTxtBox;
dgvc = (DataGridViewComboBoxColumn)dataGridInvoice.Columns["dgvProductCode"];
int indexRow = dgvc.Index;
dgTxtBox = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvProductName"];
dgTxtBox = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvPriceColumn"];
dgTxtBox = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvQuantityColumn"];
//dgvc = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvTotalColumn"];
string strText = dgvc.Selected.ToString();
string strText1 = dgvc.ValueMember.ToString();
string SelectedText = Convert.ToString((dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal = Convert.ToInt32(dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"].Value); //Format Exception
string SelectedText1 = Convert.ToString((dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal1 = Convert.ToInt32(dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"].Value);
///
///Summary
///get the id from strText1 and pass it to the procedure along with command type 'Id' to fetch data of name and price of product
DataTable dt_ProductCategory = b.BindInvoiceDataGridView(strText1, "Id");
DataGridViewTextBoxColumn dgTxtProductName = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvProductName"];
//dgTxtProductName.DataSource = dt_ProductCategory
}
public DataTable BindInvoiceDataGridView(string id,string commandtype)
{
con.Open();
cmd = new SqlCommand("sp_InvoiceDataGridViewDisplay",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@prodId", id);
cmd.Parameters.AddWithValue("@commandType", commandtype);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);
DataTable dtInvoiceDataGridViewDisplay = new DataTable();
sqlDataAdapter.Fill(dsInvoiceDataGridViewDisplay);
con.Close();
return dtInvoiceDataGridViewDisplay;
}
How to display the data in the row i.e in the text box and for the next row in the drop down list where am I going wrong ( where to make changes) ?
Please Help me !!
Thanks And Regards,
Rabbil Ahmad
"I cannot teach anybody anything. I can only make them think"~ Socrates
Thanks And Regards