Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > how to put a value in a DataGridView cell?
 

how to put a value in a DataGridView cell?

hi guys, im having problems with the DataGridView

take a look at this,

the entry starts with entering the ItemCode in the DataGridView
but after entering, it will be best to display its Description ,

i tried the events RowLeave,RowEnter,RowValidated using the following code:

            Int32 selectedRowCount = pOItemsDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);
            InventoryDataSet.POItemsRow poItRow = inventoryDataSet.POItems.NewPOItemsRow();
            poItRow.Description = Convert.ToString(itemsTableAdapter.getDescription(pOItemsDataGridView.Rows[selectedRowCount].Cells[0].Value.ToString()));
            inventoryDataSet.POItems.Rows.Add(poItRow);


i also tried using this code:

Int32 selectedRowCount = pOItemsDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);
pOItemsDataGridView.Rows[selectedRowCount].Cells[1].Value=itemsTableAdapter.getDescription(pOItemsDataGridView.Rows[selectedRowCount].Cells[0].Value.ToString()


but it didn't work, i also tested the values got, using a MessageBox and the previous data, PIN,CLIP, (which is already present the third one is the one to be added...) there's no problem
sairenji  Wednesday, August 12, 2009 3:12 AM

Hi sairenji,

You can handle the CellEnter event of the DataGridView and set the value of the cell in the second column. This is a code snippet:
private void pOItemsDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == 1 && this.pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value == null

&& this.pOItemsDataGridView[0, e.RowIndex].Value != null)

this.pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value =

itemsTableAdapter.getDescription(pOItemsDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());

}

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, August 13, 2009 9:33 AM

Try with the following code:

private
void pOItemsDataGridView_RowLeave(object sender, DataGridViewCellEventArgs e)

{

this.pOItemsDataGridView.Rows[this.pOItemsDataGridView.CurrentRow.Index].Cells[1].Value = DateTime.Now.ToString();
}

Hope it helps...

Regards,
Jahedur

Jahedur.Rahman  Thursday, August 13, 2009 9:07 AM

Hi sairenji,

You can handle the CellEnter event of the DataGridView and set the value of the cell in the second column. This is a code snippet:
private void pOItemsDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == 1 && this.pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value == null

&& this.pOItemsDataGridView[0, e.RowIndex].Value != null)

this.pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value =

itemsTableAdapter.getDescription(pOItemsDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());

}

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, August 13, 2009 9:33 AM

Hi sairenji,

You can handle the CellEnter event of the DataGridView and set the value of the cell in the second column. This is a code snippet:
private void pOItemsDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == 1 && this .pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value == null

&& this .pOItemsDataGridView[0, e.RowIndex].Value != null )

this .pOItemsDataGridView[e.ColumnIndex, e.RowIndex].Value =

itemsTableAdapter.getDescription(pOItemsDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());

}

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
hi Aland Li,

i've seen ur code snippet but it doesnt put a value in the description cell

instead i analyzed it and changed it and it worked! thanks for this suggestion!


sairenji  Friday, August 14, 2009 12:41 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView CheckBoxCell Value Changed
• DataGridView -- BindingSource isn't updated
• datagrid changing datasource at runtime not working 2nd time
• Vertical scrollbar display corruption with bound grid when changing DataSource in Scroll event handler
• Reposition to specific record using Bound controls on Windows form
• DataGridView - LastDisplayScrollingRowIndex ?
• Unable to insert a record to a table
• Threading and NewRow
• Need Better BindingSource Change Support
• Delete recorde from datagride view