Hi,
I am a beginner in windows application and I need a help.
In my DataGridView of a windows application there are multi 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.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 of Input string not in correct format.
Please have a look at the code and let me know where am I going wrong.
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"];
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);
string SelectedText1 = Convert.ToString((dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal1 = Convert.ToInt32(dataGridInvoice.Rows[indexRow].Cells["dgvProductCode"].Value);
DataTable dt_ProductCategory = b.BindInvoiceDataGridView(strText1, "Id");
DataGridViewTextBoxColumn dgTxtProductName = (DataGridViewTextBoxColumn)dataGridInvoice.Columns["dgvProductName"];
}
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;
}
public void BindingMethod()
{
DataTable dt1 = b.BindInvoiceDataGridView("", "All");
DataGridViewComboBoxColumn cbxColumn = dataGridInvoice.Columns["dgvProductCode"] as DataGridViewComboBoxColumn;
cbxColumn.DataSource = dt1;
cbxColumn.DisplayMember = "code";
cbxColumn.ValueMember = "prod_id";
}
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 !!