DataGridView, How to display data in a specific cell(Windows Application Forms)

Posted by Rodrigue30 under C# on 8/18/2010 | Points: 10 | Views : 3690 | Status : [Member] | Replies : 4
Hello to all, my problem is that i am developing a screen with a datagridview where on a row i typein a cell the code(id) of a record and then the name(description of that code in the file) is display in another specific cell on the same row and that cell will be activated at the same time, in short how can i display a text in a specific cell of a datagridview.




Responses

Posted by: T.saravanan on: 8/18/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Rodrigue30,

Step1:
//Declare a object Globally
EventHandler dgv_TextChanged;
Control IdVal;

Step2:
// Select EditingControlShowing Event from DataGridView
//Give the following coding in this event
dgv_TextChanged=new EventHandler(dgv_TextChanged);
IdVal=e.Control;
IdVal.TextChanged +=dgv_TextChanged;

Step3:
//Create a dgv_TextChanged Event
//Give a Codition in this Event & To get a RowIndex from DataGridView

if(IdVal.Text !=string.Empty)
{
//To pass the IdVal in to your condition and get the Name
dgv.rows[RowIndex].Cells["Name"].Value="Name";
}

dgv -->DataGridView

If any queries ask to me.

Thanks, :)
T.Saravanan









Thanks,
T.Saravanan

Rodrigue30, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rodrigue30 on: 8/18/2010 [Member] Starter | Points: 25

Up
0
Down
Thanks, i will try it and let you know the output.

Rodrigue30, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rodrigue30 on: 8/18/2010 [Member] Starter | Points: 25

Up
0
Down
Hi T. saravanan,
i am verry new to c#, i do understand the step1, part of step2, However my problem is this first i don't know if i am using the right control, i am designing a screen to produce an invoice and i am using DataGridView and what i will like to do is thas on a row the user type the code of un item in the first cell and when that cell looses focus the cursor moves to the next cell and at the same time the name(the description of that code in cell 1) is displayed in that cell (next cell).

Rodrigue30, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 8/18/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Rodrigue30,

If u need cell leave means u will use cellEndEdit Event.
In CellEndEdit event to find RowIndex and ColumnIndex and set the Name value in that same row in particular column.

Ex:
string sIdVal=dgv.Rows[e.RowIndex].Cells["ID"].Value.ToString();
// To Pass sIdVal and get Name
//Assign the Value into your Column
dgv.Rows[e.RowIndex].Cells["Name"].Value="Name";


Thanks,
T.Saravanan

Rodrigue30, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response