Hi,
I want to display certain rows readonly & change back color of a datagridview & displayed as the grid gets populated
The problem i have is that I'm using the RowEnter Event - which works when the user selects a row
But i whant it to be displayed on the grid visually without selecting a row - when grid gets populated:
private void dgvDetail_RowEnter(object sender, DataGridViewCellEventArgs e)
{dgvCurrentRow = dgvDetail.Rows[e.RowIndex];
if (oLOTXLOCXID_Row["WhsLPNo"].ToString() == "Found")
{dgvCurrentRow.DefaultCellStyle.BackColor = this.BackColor;
dgvCurrentRow.DefaultCellStyle.ForeColor = SystemColors.GrayText;
dgvCurrentRow.ReadOnly = true;
dgvCurrentRow.Cells[10].Value = 1;}}
Please Help!
Loading
naura paxPosted Oct 1, 2009, 6:56 AM
If the column is there and you still can't get any value, you'll have to check the
DataPropertyName property of the column and it should match the name of the column in you underlying datatable.
I hope i'm clear this time.
ic icPosted Oct 1, 2009, 7:27 AM
Once again Thanks - Until Later
naura paxPosted Oct 1, 2009, 7:13 AM
ic icPosted Oct 1, 2009, 7:08 AM
I done exactly that add column to grid
if (dgvCurrentRow.Cells[12].Value.ToString() == "Found")
Thank You :)
ic icPosted Oct 1, 2009, 6:43 AM
I'm using the RowsAdded event, it goes through the grid rows.
But i have to test for a value in the the underlying data of the grid - (that is not displayed on the grid) to set the style.
for (int i = 0; i < e.RowCount; ++i){
dgvCurrentRow = dgvDetail.Rows[i + e.RowIndex];
* if (dgvDetail.CurrentRow.DataGridView.CurrentRow. == "Found") *
I can't get hold of the column to check the alue I can see it on the databinding - current row - when i put a break but actually coding is difficult.
The column exists in my table but not displayed on my grid and i'm going through the grid!
Please Assist - I have to get this going!
Regards
naura paxPosted Oct 1, 2009, 6:30 AM
dgvDetail[i].DefaultCellStyle.BackColor = Color.Red;
I am getting confused about your actual problem now.
ic icPosted Oct 1, 2009, 6:23 AM
I tried again but unsuccessful
for (int i = 0; i < 1; ++i) //does not work
{ dgvCurrentRow = dgvDetail[i]; //does not work
dgvCurrentRow.DefaultCellStyle.BackColor = this.BackColor;
naura paxPosted Oct 1, 2009, 5:49 AM
what does... 'Could it be that the oLOTXLOCXID_BS only occurs once for the first record if so how do i check a value of a grid row ??' means?.
Is oLOTXLOCXID_BS a datatable. You need to check your logic as well, the string that you are matching must be there in all records.
and in case of DataBindComplete event you don't need [i+e.RowIndex].. you just have to scroll through all records using grd[i].
ic icPosted Oct 1, 2009, 5:20 AM
on the rowsadded event: it loops through the same record all the time & sets only the first match
if (oLOTXLOCXID_BS.Current != null)
{oLOTXLOCXID_Row = (DataRowView)oLOTXLOCXID_BS.Current;
if (dgvDetail.CurrentRow != null){
for (int i = 0; i < e.RowCount; ++i){
dgvCurrentRow = dgvDetail.Rows[i + e.RowIndex];
if (oLOTXLOCXID_Row["WhsLPNo"].ToString() == "Found")
{dgvCurrentRow.ReadOnly = true;dgvCurrentRow.Cells[10].Value = 1;}
Could it be that the oLOTXLOCXID_BS only occurs once for the first record if so how do i check a value of a grid row ??
naura paxPosted Oct 1, 2009, 3:56 AM
If row is added programmitally in dataset for that case RowAdded event works apart from that there is also UserAddedRow event which works when user is allowed to enter a row.
i hope you'll get through with it.
Nir BarPosted Oct 1, 2009, 3:46 AM
The RowsAdded event is triggered once for several rows
You should iterate the rows like this:
for( int i = 0; i < e.RowCount; ++i)
{
dataGridView1.Rows[i + e.RowIndex] ...
}
Please mark this post as an answer if it helps you
Nir
ic icPosted Oct 1, 2009, 3:41 AM
I put a break on the event & it only entered the event twice & it worked only for the second row.
Others not - it did not even go to the event for the other rows.
So out of the 4 rows that showed have been visibly disabled only the second row was disabled
?
naura paxPosted Oct 1, 2009, 3:09 AM
you should write that code on row_added event.
that way effect will be given each time a row is added in the grid.