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 paxRank #2,843 · 502 reputationPosted Oct 1, 2009, 2:56 AM EDT
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.
naura paxRank #2,843 · 502 reputationPosted Sep 30, 2009, 11:09 PM EDT
you should write that code on row_added event.
that way effect will be given each time a row is added in the grid.
ic ic80 reputationPosted Sep 30, 2009, 11:41 PM EDT
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
?
Nir Bar107 reputationPosted Sep 30, 2009, 11:46 PM EDT
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
naura paxRank #2,843 · 502 reputationPosted Sep 30, 2009, 11:56 PM EDT
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.
ic ic80 reputationPosted Oct 1, 2009, 1:20 AM EDT
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 paxRank #2,843 · 502 reputationPosted Oct 1, 2009, 1:49 AM EDT
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 ic80 reputationPosted Oct 1, 2009, 2:23 AM EDT
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 paxRank #2,843 · 502 reputationPosted Oct 1, 2009, 2:30 AM EDT
dgvDetail[i].DefaultCellStyle.BackColor = Color.Red;
I am getting confused about your actual problem now.
ic ic80 reputationPosted Oct 1, 2009, 2:43 AM EDT
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
ic ic80 reputationPosted Oct 1, 2009, 3:08 AM EDT
I done exactly that add column to grid
if (dgvCurrentRow.Cells[12].Value.ToString() == "Found")
Thank You :)
naura paxRank #2,843 · 502 reputationPosted Oct 1, 2009, 3:13 AM EDT
ic ic80 reputationPosted Oct 1, 2009, 3:27 AM EDT
Once again Thanks - Until Later