ANINDYA
asked on
DatagridviewColumnButton Color setting
Experts
Please see the attached image and tell me how to set a specific color to specific datagridviewcoloumButton.
I am using VS 2008
Thanking you
Anindya
error.JPG
Please see the attached image and tell me how to set a specific color to specific datagridviewcoloumButton.
I am using VS 2008
Thanking you
Anindya
error.JPG
check this examlpe changing color:DataGridViewCellStyl e currentIDCellStyle = new DataGridViewCellStyle(curr entRow.Cel ls["ID"].S tyle);curr entIDCellS tyle.BackC olor = FormUtilities.editedRowIDC ellColor;c urrentIDCe llStyle.Se lectionBac kColor = FormUtilities.editedRowIDC ellSelecti onColor;cu rrentRow.C ells["ID"] .Style = currentIDCellStyle;(http://www.mycsharp.de/wbb2/thread.php?postid=149991)
to set the coloumheader button in datagridview, chec this example: // Set the column default header style. DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColo r = Color.Aqua; columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold); dataGridView.ColumnHeaders DefaultCel lStyle = columnHeaderStyle;//set specfic coloum header styleDataGridViewColumn column = dataGridView.Columns[0]; DataGridViewCell cell = new DataGridViewTextBoxCell(); cell.Style.BackColor = Color.Wheat;cell.Style.For eColor = Color.Green; column.CellTemplate = cell;
hi
Are you creating a Bar Graph Column?
if you are try to see this link;
http://www.codeproject.com/KB/webforms/graphdatagrid.aspx
And if your not, can you expound or elaborate your problem.
Are you creating a Bar Graph Column?
if you are try to see this link;
http://www.codeproject.com/KB/webforms/graphdatagrid.aspx
And if your not, can you expound or elaborate your problem.
I think "sedgwick" got the solution, but if that's not, please expound or elaborate again.
ASKER
Expert sedgwick
Thank for the response.
Sir I am not getting the required result as I am perhaps using it in the wrong way..
please see the code below.....
Can you please suggest me what I have to write inside the
case block so that only the 1st datagridview button should become colored.
private void Form1_Load(object sender, EventArgs e)
{
show_reminders();
using (SqlConnection con = new SqlConnection(Connectionst ring.Conne ction))
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate] from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
//setButtonColor(ds.Tables [0]);
setcolor(ds.Tables[0], e);
}
}
}
private void setcolor(DataTable dataTable, EventArgs e)
{
foreach (DataRow row in dataTable.Rows)
{
foreach (DataColumn col in dataTable.Columns)
{
//dataGridView1.Columns.In dexOf[
for (Int32 i = 0; i <= 3; i++)
{
switch (row[col].ToString())
{
case "0": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "1":
dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "2": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "3":
DataGridViewCellStyle currentIDCellStyle = new DataGridViewCellStyle(row. Cells[0].S tyle);
//currentIDCellStyle.BackC olor = dataGridView1.editedRowIDC ellColor;
//currentIDCellStyle.Selec tionBackCo lor = dataGridView1.editedRowIDC ellSelecti onColor;
currentRow.Cells["ID"].Sty le = currentIDCellStyle;
break;
case "4": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "5": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "6": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "7": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "8": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "9": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
case "10": dataGridView1.CurrentRow.C ells[0].St yle.ForeCo lor = Color.Green;
break;
default:
break;
}
}
}
}
}
Thanking you
Thanks for the response.
Anindya
Thank for the response.
Sir I am not getting the required result as I am perhaps using it in the wrong way..
please see the code below.....
Can you please suggest me what I have to write inside the
case block so that only the 1st datagridview button should become colored.
private void Form1_Load(object sender, EventArgs e)
{
show_reminders();
using (SqlConnection con = new SqlConnection(Connectionst
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate] from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
//setButtonColor(ds.Tables
setcolor(ds.Tables[0], e);
}
}
}
private void setcolor(DataTable dataTable, EventArgs e)
{
foreach (DataRow row in dataTable.Rows)
{
foreach (DataColumn col in dataTable.Columns)
{
//dataGridView1.Columns.In
for (Int32 i = 0; i <= 3; i++)
{
switch (row[col].ToString())
{
case "0": dataGridView1.CurrentRow.C
break;
case "1":
dataGridView1.CurrentRow.C
break;
case "2": dataGridView1.CurrentRow.C
break;
case "3":
DataGridViewCellStyle currentIDCellStyle = new DataGridViewCellStyle(row.
//currentIDCellStyle.BackC
//currentIDCellStyle.Selec
currentRow.Cells["ID"].Sty
break;
case "4": dataGridView1.CurrentRow.C
break;
case "5": dataGridView1.CurrentRow.C
break;
case "6": dataGridView1.CurrentRow.C
break;
case "7": dataGridView1.CurrentRow.C
break;
case "8": dataGridView1.CurrentRow.C
break;
case "9": dataGridView1.CurrentRow.C
break;
case "10": dataGridView1.CurrentRow.C
break;
default:
break;
}
}
}
}
}
Thanking you
Thanks for the response.
Anindya
private void Form1_Load(object sender, EventArgs e)
{
show_reminders();
using (SqlConnection con = new SqlConnection(Connectionstring.Connection))
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate] from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
//setButtonColor(ds.Tables[0]);
setcolor(ds.Tables[0], e);
}
}
}
private void setcolor(DataTable dataTable, EventArgs e)
{
foreach (DataRow row in dataTable.Rows)
{
foreach (DataColumn col in dataTable.Columns)
{
//dataGridView1.Columns.IndexOf[
for (Int32 i = 0; i <= 3; i++)
{
switch (row[col].ToString())
{
case "0": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "1":
dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "2": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "3":
DataGridViewCellStyle currentIDCellStyle = new DataGridViewCellStyle(row.Cells[0].Style);
//currentIDCellStyle.BackColor = dataGridView1.editedRowIDCellColor;
//currentIDCellStyle.SelectionBackColor = dataGridView1.editedRowIDCellSelectionColor;
currentRow.Cells["ID"].Style = currentIDCellStyle;
break;
case "4": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "5": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "6": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "7": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "8": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "9": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
case "10": dataGridView1.CurrentRow.Cells[0].Style.ForeColor = Color.Green;
break;
default:
break;
}
}
}
}
}
ANINDYA;
Is it fixed?
"Sedgwick" is not listening for this time
Is it fixed?
"Sedgwick" is not listening for this time
>>1st datagridview button should become colored.
do you mean the first column header button, right?
do you mean the first column header button, right?
ASKER
Expert sedgwick and Expert Systan
I am extremely sorry for not responding to you at the specified time .
Actually it was weekends in India so I had not come to office.
Experts here is what I am trying but not getting
using (SqlConnection con = new SqlConnection(Connectionst ring.Conne ction))
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate],Opportunity_ID from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
foreach (DataRow dr in ds.Tables["Table_Opportuni ty"].Rows)
{
int rate = 0;
rate = Convert.ToInt32(dr["Rate"] .ToString( ));
switch (rate)
{
case 0:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
//Experts here I have created dgvbtncol now I want to set the dgvbtncol. color to be as I am going to specify. but I am not getting what code to write so that the button should get the color
break;
case 1:
DataGridViewButtonColumn DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 2:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 3:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 4:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 5:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 6:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 7:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 8:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 9:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
case 10:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn() ;
break;
default:
MessageBox.Show("Please check there is an Opportunity which has no Rate stated.");
break;
}
}
}
}
Experts here I have created dgvbtncol now I want to set the dgvbtncol. color to be as I am going to specify. but I am not getting what code to write so that the button should get the color
I am extremely sorry for not responding to you at the specified time .
Actually it was weekends in India so I had not come to office.
Experts here is what I am trying but not getting
using (SqlConnection con = new SqlConnection(Connectionst
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate],Opportunity_ID from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
foreach (DataRow dr in ds.Tables["Table_Opportuni
{
int rate = 0;
rate = Convert.ToInt32(dr["Rate"]
switch (rate)
{
case 0:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
//Experts here I have created dgvbtncol now I want to set the dgvbtncol. color to be as I am going to specify. but I am not getting what code to write so that the button should get the color
break;
case 1:
DataGridViewButtonColumn DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 2:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 3:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 4:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 5:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 6:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 7:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 8:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 9:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
case 10:
DataGridViewButtonColumn dgvbtncol = new DataGridViewButtonColumn()
break;
default:
MessageBox.Show("Please check there is an Opportunity which has no Rate stated.");
break;
}
}
}
}
Experts here I have created dgvbtncol now I want to set the dgvbtncol. color to be as I am going to specify. but I am not getting what code to write so that the button should get the color
ASKER
Expert sedgwick
please glance upon this code and see what is going wrong
private void populate_opportunityDTGDV( )
{
using (SqlConnection con = new SqlConnection(Connectionst ring.Conne ction))
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate],Opportunity_ID from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
if (dataGridView1.Columns["Ra teStatus"] == null)
{
DataGridViewButtonColumn col = new DataGridViewButtonColumn() ;
col.HeaderText = "RateStatus";
col.Name = "RateStatus";
dataGridView1.Columns.Add( col);
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<Da taGridView Row>())
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr .Cells["Ra teStatus"] ;
if (dr.Cells["Rate"].Value != null)
{
btnCell.Value = int.Parse(dr.Cells["Rate"] .Value.ToS tring()) <= 5 ? "Low" : "High";
}
}
if (dataGridView1.Columns["Bu sinessPros pect"] == null)
{
DataGridViewButtonColumn col2 = new DataGridViewButtonColumn() ;
col2.HeaderText = "BusinessProspect";
col2.Name = "BusinessProspect";
dataGridView1.Columns.Add( col2);
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<Da taGridView Row>())
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr .Cells["Bu sinessPros pect"];
if (dr.Cells["Rate"].Value != null)
{
int BusinessProspectRate = 0;
BusinessProspectRate = int.Parse(dr.Cells["Rate"] .Value.ToS tring());
switch (BusinessProspectRate)
{
case 1:
//DataGridViewCell cell = new DataGridViewTextBoxCell();
btnCell.Style.BackColor = Color.Pink;
//cell.Style.ForeColor = Color.Green;
//column.CellTemplate = cell;
//DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
//columnHeaderStyle.BackCo lor = Color.Aqua;
//columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
//dataGridView1.ColumnHead ersDefault CellStyle = columnHeaderStyle;
break;
//case 2:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 3:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 4:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 5:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 6:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 7:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 8:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 9:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
//case 10:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo r = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader sDefaultCe llStyle = columnHeaderStyle;
// break;
default:
break;
}
}
}
}
}
}
please glance upon this code and see what is going wrong
private void populate_opportunityDTGDV(
{
using (SqlConnection con = new SqlConnection(Connectionst
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate],Opportunity_ID from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
if (dataGridView1.Columns["Ra
{
DataGridViewButtonColumn col = new DataGridViewButtonColumn()
col.HeaderText = "RateStatus";
col.Name = "RateStatus";
dataGridView1.Columns.Add(
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<Da
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr
if (dr.Cells["Rate"].Value != null)
{
btnCell.Value = int.Parse(dr.Cells["Rate"]
}
}
if (dataGridView1.Columns["Bu
{
DataGridViewButtonColumn col2 = new DataGridViewButtonColumn()
col2.HeaderText = "BusinessProspect";
col2.Name = "BusinessProspect";
dataGridView1.Columns.Add(
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<Da
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr
if (dr.Cells["Rate"].Value != null)
{
int BusinessProspectRate = 0;
BusinessProspectRate = int.Parse(dr.Cells["Rate"]
switch (BusinessProspectRate)
{
case 1:
//DataGridViewCell cell = new DataGridViewTextBoxCell();
btnCell.Style.BackColor = Color.Pink;
//cell.Style.ForeColor = Color.Green;
//column.CellTemplate = cell;
//DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
//columnHeaderStyle.BackCo
//columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
//dataGridView1.ColumnHead
break;
//case 2:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 3:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 4:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 5:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 6:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 7:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 8:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 9:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
//case 10:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColo
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeader
// break;
default:
break;
}
}
}
}
}
}
private void populate_opportunityDTGDV()
{
using (SqlConnection con = new SqlConnection(Connectionstring.Connection))
{
string query = "select Opportunity_Title as [Name of Opportunity],Rate as [Rate],Opportunity_ID from Table_Opportunity";
using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
{
DataSet ds = new DataSet();
ad.Fill(ds, "Table_Opportunity");
dataGridView1.DataSource = ds.Tables[0];
if (dataGridView1.Columns["RateStatus"] == null)
{
DataGridViewButtonColumn col = new DataGridViewButtonColumn();
col.HeaderText = "RateStatus";
col.Name = "RateStatus";
dataGridView1.Columns.Add(col);
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<DataGridViewRow>())
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr.Cells["RateStatus"];
if (dr.Cells["Rate"].Value != null)
{
btnCell.Value = int.Parse(dr.Cells["Rate"].Value.ToString()) <= 5 ? "Low" : "High";
}
}
if (dataGridView1.Columns["BusinessProspect"] == null)
{
DataGridViewButtonColumn col2 = new DataGridViewButtonColumn();
col2.HeaderText = "BusinessProspect";
col2.Name = "BusinessProspect";
dataGridView1.Columns.Add(col2);
}
foreach (DataGridViewRow dr in dataGridView1.Rows.Cast<DataGridViewRow>())
{
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dr.Cells["BusinessProspect"];
if (dr.Cells["Rate"].Value != null)
{
int BusinessProspectRate = 0;
BusinessProspectRate = int.Parse(dr.Cells["Rate"].Value.ToString());
switch (BusinessProspectRate)
{
case 1:
//DataGridViewCell cell = new DataGridViewTextBoxCell();
btnCell.Style.BackColor = Color.Pink;
//cell.Style.ForeColor = Color.Green;
//column.CellTemplate = cell;
//DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
//columnHeaderStyle.BackColor = Color.Aqua;
//columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
//dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
break;
//case 2:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 3:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 4:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 5:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 6:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 7:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 8:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 9:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
//case 10:
// DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
// columnHeaderStyle.BackColor = Color.Aqua;
// columnHeaderStyle.Font =
// new Font("Verdana", 10, FontStyle.Bold);
// dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// break;
default:
break;
}
}
}
}
}
}
you want the button itself colored, or the background of the cell of the gridview be colored?
Untitled.jpg
Untitled.jpg
ASKER
button to be colored
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Expert sedgwick
I have no word to express my gratitude towards you.
My problems are solved .
But the most important fact is the way you have done so is amazing as it is too in midnight hours of your country.
I will be grateful to you if you provide me your email id so that next time when I will put any query in EE I can provide you the URL and thereafter it is your wish to respond or not to do so.
But at least I want to provide you the URL.
If you think I am worth so then please provide me your email id . my email id is anindya002@gmail.com
I do assure you I will not disturb you by any other means .
Only URL s of the EE I will forward to you.
Please kindly consider my request.
In last 6 months I have not seen an expert like you who has rendered so much of help to me.
Any way Thanking you for your benevolence towards me.
Anindya Chatterjee
Bangalore
India
I have no word to express my gratitude towards you.
My problems are solved .
But the most important fact is the way you have done so is amazing as it is too in midnight hours of your country.
I will be grateful to you if you provide me your email id so that next time when I will put any query in EE I can provide you the URL and thereafter it is your wish to respond or not to do so.
But at least I want to provide you the URL.
If you think I am worth so then please provide me your email id . my email id is anindya002@gmail.com
I do assure you I will not disturb you by any other means .
Only URL s of the EE I will forward to you.
Please kindly consider my request.
In last 6 months I have not seen an expert like you who has rendered so much of help to me.
Any way Thanking you for your benevolence towards me.
Anindya Chatterjee
Bangalore
India
dear Anindya
thank you for your warm gratitude.
it's not necessary for you to email me when you put new question on EE cause i'm tracking down all new questions which are in my favorite zones (C# is one of many).
i'll make sure to provide you a fast and proper solution to any of your future questions as well.
thanks again and take care.
-sedgwick
thank you for your warm gratitude.
it's not necessary for you to email me when you put new question on EE cause i'm tracking down all new questions which are in my favorite zones (C# is one of many).
i'll make sure to provide you a fast and proper solution to any of your future questions as well.
thanks again and take care.
-sedgwick
ASKER
Expert sedgwick
If possible please write a blog on EE on
1. How to connect ASP .net MVC to Sql server 2008.
Thanking you,
Anindya
If possible please write a blog on EE on
1. How to connect ASP .net MVC to Sql server 2008.
Thanking you,
Anindya