Link to home
Start Free TrialLog in
Avatar of dcl120748
dcl120748Flag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I make a single cell in a DataTable ReadOnly?

I am creating a DataTable from a DataReader and conditionally I can make a column ReadOnly as below. However how can I make just a cell in that row ReadOnly rather than the whole column?

 while (rdr.Read())
 {
         DataRow dr = dt.NewRow();
         if (rdr.GetDateTime(8).ToString().Equals("01/01/1900 00:00:00"))
                        {
                            dr[8] = false;
                        }
                        else
                        {
                            dr[8] = true;
                            dt.Columns[8].ReadOnly = true;
                        }
          dt.Rows.Add(dr);
}

Thanks,
Dee
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

myDataColumn = New DataColumn()
myDataColumn = DataTable.Columns(8)
myDataColumn.Readonly= true

Hope this helps
Avatar of dcl120748

ASKER

Thanks for that Masteraco and perhaps I am misunderstanding but wouldn't that make the whole column ReadOnly and not just the cell? What I need is for the cell contained on that particular row at column 8 to be ReadOnly.
ASKER CERTIFIED SOLUTION
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got it. Many thanks.