How to fill textcolumn value in datagridview
Hi Friends,
I am working with datagridview control in window application. This gridview has two comboboxcolumn and one textbox column.
Now i want to enter predefien value in the textboxcell when second combo box item changed.
So please give any idea about how to do so. In which event i will get changed value of combo box ?
Kirtan PatelPosted Dec 2, 2009, 1:58 PM
if my answer helps you then check "Do you like this answer" check box :)
There is No Event for That Combo box inside the DataGridView for SelectedIndexChanged So you have to write your
own Event for that combobox if you are advance user then check the reply of "Aland Li" for how to build that event in
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/fbc2df27-ff27-44a2-99af-edb3e7705c20
Else Do below Procedure
Solution to This Problem (changes the value of textboxcell when user end editing)
---------------------------------------------
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int colIndex = e.ColumnIndex;
int rowindex = e.RowIndex;
//Suppose your Combobox Column index is 1
try
{
if (e.ColumnIndex == 1)
{
string ComboxSelectedValue = dataGridView1.Rows[rowindex].Cells[colIndex].Value.ToString();
if (ComboxSelectedValue == "Item1")
{
//Do somthing
dataGridView1.Rows[rowindex].Cells[0].Value = "Ietm 1 Selected";
}
else if (ComboxSelectedValue == "Item2")
{
//Do somthing
dataGridView1.Rows[rowindex].Cells[0].Value = "Ietm 2 Selected";
}
}
}
catch
{
}
}
Sam HobbsPosted Dec 2, 2009, 9:18 PM
Sam HobbsPosted Dec 2, 2009, 3:17 PM
Are you using a DataGridViewComboBoxCell for the column? I assume you are.
You can process the CellValueChanged event of the DataGridView. This event occurs when the current cell changes. If you don't need to process the event that happens when the value shown in the ComboBox changes, then you can at least set the TextBox to the corresponding value when the ComboBox has changed and the user moves to a different cell. In the following code for the CellValueChanged event of the DataGridView, column index 1 is a DataGridViewComboBoxCell. This code will copy it's value to cell 0, but you can process the cell's contents however you need to.
avani ravalPosted Dec 2, 2009, 4:28 AM
Sam HobbsPosted Dec 1, 2009, 12:02 PM