Problem in datagridtextbox column
-
hell sir, i am working on datagrid control in c# window application i use datagridtextbox in datagrid . my probblem is that how can i do datagrid textbox column enable=false if it contains data =sunday my code is... try { dataGrid1.DataSource=null; dt.Clear(); dataGrid1.TableStyles.Clear(); ad=new SqlDataAdapter("select * from attendance where months='"+txtmonth.Text+"' and class='"+txtcurrentclass.Text+"' and section='"+txtsection.Text+"' and session='"+Class1.session+"'",cn); ad.Fill(dt); dt.Tables[0].DefaultView.AllowNew=false; dataGrid1.DataSource=dt.Tables[0]; DataGridTableStyle tbl=new DataGridTableStyle(); tbl.MappingName=dt.Tables[0].TableName; DataGridTextBoxColumn txt=new DataGridTextBoxColumn(); // txt.MappingName=dt.Tables[0].Columns["id"].ColumnName; // txt.HeaderText="SNo."; // txt.TextBox.BorderStyle=BorderStyle.FixedSingle; // txt.TextBox.Enabled=false; // txt.ReadOnly=true; // txt.Width=45; // txt.TextBox.BackColor=Color.Salmon; // txt.NullText="0"; // // tbl.GridColumnStyles.Add(txt); // txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns["Studentcode"].ColumnName; txt.HeaderText="Student Code"; txt.ReadOnly=true;txt.TextBox.BorderStyle=BorderStyle.FixedSingle;txt.TextBox.BackColor=Color.Salmon; txt.TextBox.Enabled=false; txt.TextBox.WordWrap=true; txt.Width=160; txt.Alignment=HorizontalAlignment.Left; tbl.GridColumnStyles.Add(txt); // txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns["studentname"].ColumnName; txt.HeaderText="Name"; txt.TextBox.BorderStyle=BorderStyle.FixedSingle; txt.TextBox.Enabled=false; txt.TextBox.BackColor=Color.Salmon; txt.TextBox.ForeColor=Color.Blue; txt.ReadOnly=true; txt.Width=80; txt.Alignment=HorizontalAlignment.Center; tbl.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns[4].ColumnName; txt.HeaderText="1 "+txtmonth.Text; txt.TextBox.BorderStyle=BorderStyle.FixedSingle;txt.Alignment=HorizontalAlignment.Center; txt.Width=65; if(txt.TextBox.Text==DayOfWeek.Sunday.ToString()) { txt.ReadOnly=true; txt.TextBox.BackColor=Color.Red; } else { txt.ReadOnly=false; txt.TextBox.BackColor=Color.White; } tbl.GridC
-
hell sir, i am working on datagrid control in c# window application i use datagridtextbox in datagrid . my probblem is that how can i do datagrid textbox column enable=false if it contains data =sunday my code is... try { dataGrid1.DataSource=null; dt.Clear(); dataGrid1.TableStyles.Clear(); ad=new SqlDataAdapter("select * from attendance where months='"+txtmonth.Text+"' and class='"+txtcurrentclass.Text+"' and section='"+txtsection.Text+"' and session='"+Class1.session+"'",cn); ad.Fill(dt); dt.Tables[0].DefaultView.AllowNew=false; dataGrid1.DataSource=dt.Tables[0]; DataGridTableStyle tbl=new DataGridTableStyle(); tbl.MappingName=dt.Tables[0].TableName; DataGridTextBoxColumn txt=new DataGridTextBoxColumn(); // txt.MappingName=dt.Tables[0].Columns["id"].ColumnName; // txt.HeaderText="SNo."; // txt.TextBox.BorderStyle=BorderStyle.FixedSingle; // txt.TextBox.Enabled=false; // txt.ReadOnly=true; // txt.Width=45; // txt.TextBox.BackColor=Color.Salmon; // txt.NullText="0"; // // tbl.GridColumnStyles.Add(txt); // txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns["Studentcode"].ColumnName; txt.HeaderText="Student Code"; txt.ReadOnly=true;txt.TextBox.BorderStyle=BorderStyle.FixedSingle;txt.TextBox.BackColor=Color.Salmon; txt.TextBox.Enabled=false; txt.TextBox.WordWrap=true; txt.Width=160; txt.Alignment=HorizontalAlignment.Left; tbl.GridColumnStyles.Add(txt); // txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns["studentname"].ColumnName; txt.HeaderText="Name"; txt.TextBox.BorderStyle=BorderStyle.FixedSingle; txt.TextBox.Enabled=false; txt.TextBox.BackColor=Color.Salmon; txt.TextBox.ForeColor=Color.Blue; txt.ReadOnly=true; txt.Width=80; txt.Alignment=HorizontalAlignment.Center; tbl.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName=dt.Tables[0].Columns[4].ColumnName; txt.HeaderText="1 "+txtmonth.Text; txt.TextBox.BorderStyle=BorderStyle.FixedSingle;txt.Alignment=HorizontalAlignment.Center; txt.Width=65; if(txt.TextBox.Text==DayOfWeek.Sunday.ToString()) { txt.ReadOnly=true; txt.TextBox.BackColor=Color.Red; } else { txt.ReadOnly=false; txt.TextBox.BackColor=Color.White; } tbl.GridC
Investigate the OnCellPaint event handling.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”