.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Unable to modify cell color in DataGridView (C#)

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :.NET Framework
 

Hi,

I have a Datagridview object contained in a TabPage and which gets its data from a DataTable.

I'd like to modify the background color of some cells under some asumptions. But I only see the value change in my cell, not the color change. If I go into the datagridview object, I can see the color has been modified, it just doesn't appear on the screen. I have tried to invalidate everything.

Thanks.

 

 

 for (int i =0; i<dgViewObject.Rows.Count; i++)
{
  if( (string) dgViewObject.Rows[i].Cells[2].Value == "SELL")
 {  dgViewObject.Rows[i].Cells[2].Value = "SELL TEST";
   dgViewObject.Rows[i].Cells[2].Style.BackColor = Color.Red; 
 }   }

 

 





View Complete Post


More Related Resource Links

Unable to modify Maintenance Plans SQL 2008

  
Been having a problem for a while, in that we are unable to modify any maintenance plans in SQL Server Management Studio. The server is running SLQ Server 2008 Standard on Windows 2003 Standard SP2

How to Change the Color of Link Label which is a Datagridview Column on a Row Selection?

  
Hi All I have a Link label as one of the column of Datagridview & also my SelectionBackColor set to Blue. Is there any way that i can change the link label color on a particular row selection as now my selectionbackcolor & link label color is matching...I am unable to the contents of that link label column. Should i do this on design level or in code level? Pls Help

How to make a DataGridView Cell/Column not enterable / selecatble

  
Hi, I am trying to make a Column in a DataGridView non-entaerable (the user should not be able to set focus to the cell neither using the mouse nor the keyboard). I already tried to change the CurrentCell property in the CellStateChanged. But in this event-handler the CurrenCell is the "old" one; setting it to any value doesn't help, because the value is set after calling this procedure. In Delphi there is an event-handler for entering a cell, where you can tell whether the user is allowed to enter a cell. Is there anything comparable in C#? Any other suggestions?

Can't modify color theme after cross product upgrade

  
Alright, I'm at wit's end.  I upgraded my MSSX 2008 (based on WSS 3.0sp2) to Sharepoint server 2010 via a database attach.  I sorted out all the preupgradecheck stuff and confirmed that the database upgraded status shows up as completed.  Everything seems to work fine except that when I go to Site Theme for any of the site collections that were upgraded, I do not get the option below the themes to customize the colors.  This occurs even if I've commited to the Visual upgrade (v4).  It'll let you choose an existing color theme but there's nothing below that area.  It also occurs if I create a new sub site of an upgraded site collection.  But if I create a brand new top level site collection, then I get the color customization options below the theme list.  I've confirmed in powershell that the sites in question show the UIVersion as 4 and the change flag is set to false which is normal.  I also tried forcing the Update() to run on the SPSite object from powershell as well.  I looked at one of the sites with designer 2010 and there are still some v3 files/folders in there.  I also tried the Reset to Site Definition but to no avail. So what I'm trying to figure out is this color customization problem a bug, known issue, or a sign that my upgrade is incomplete?  Any help would be much appreciated. 

datagridview select cell

  

okay, this is driving me crazy!!!

In my datagridview, on the current row, how do I select/set the focus of a particular cell?  I am already on the row I just want to set the focus to the third cell.

 

after I validate a cetain cell, I want to tab to the next cell

I tried:

 

SendKeys.Send("{TAB}")  and the application stalls

 

I tried:

 

DgvSched.CurrentCell = DgvSched[3, DgvSched.CurrentRow.Index];

and also

DgvSched.CurrentCell = DgvSched[3, e.RowIndex];

and I get the following error:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

 

when I remove the above statement the error does not come up.

 

Anybody??!!


 


Find out if DatagridView Cell is Clicked

  

I have 2 grids on a form.

Both grids are binded to object Panel and PanelLines.

If user click first panel grid, the second panel line grid will show the related panel lines.

If the user clicks the panel grid on the same cell again, I want panel line grid to scroll rows as such visible rows hide and bottom rows show up.

The following code does the scrolling part.

dgvPanelItem.FirstDisplayedScrollingRowIndex = dgvPanelItem.DisplayedRowCount(False) - 1
But I need help in finding out, if first grid ( panel grid ) is already clicked or not.

Find out if DatagridView Cell is Clicked

  

I have 2 grids on a form.

Both grids are binded to object Panel and PanelLines.

If user click first panel grid, the second panel line grid will show the related panel lines.

If the user clicks the panel grid on the same cell again, I want panel line grid to scroll rows as such visible rows hide and bottom rows show up.

The following code does the scrolling part.

dgvPanelItem.FirstDisplayedScrollingRowIndex = dgvPanelItem.DisplayedRowCount(False) - 1
But I need help in finding out, if first grid ( panel grid ) is already clicked or not.

Painting/Filling a specific cell using CellPainting event of datagridview

  

Hi,

I am trying to paint a quantity column in data grid with color red, however when I do so cell alignment changes to left. 

Seems like I have to convert e.value to string in order for this to work and when I do that the cell alignment changes.

Quantity column is of type decimal.

Also I would appreciate if you can guide on how i can fill the certain columns in data grid with certain color(for ex. yellow).

 if (this.dtaGridView.Columns[7].Index ==e.ColumnIndex && e.RowIndex >= 0)

      

             {

                 

handle up & down keys while editing a cell in datagridview to affect listbox

  

I have a datagridview. i have overridden some datagridview methods to capture enter key and updown key in a separate class

ProcessDialogKey()

ProcessDataGridViewKey()

i also have a listbox. while i am editing a cell the listbox is being visible and searching in the listbox for what is in the cell's textbox. (i am also able to catch the up down key but from a different class which overrides some methods.)

Now what i need is when i press up and down key the listbox's selected items will change accordingly.

Plz help me to solve it.


How to change the datagrid cell background color linear to the value

  

Hi,

I have a WPF 4.0 Datagrid displaying order values and I need to colour the backgroud of the high value orders so the user will notice high value orders easily. Is it possible to set the colour from white to red but increasing in steps say every 10,000 and increase the colour intensity according to the value.

Many Thanks.

Vijay


DataGridView & Custom cell painting

  

I'm creating a schedule using a datagridview.  The cells in the grid need a lot of special behavour so I created my own Column and Cell classes.  In the Cell.Paint method I draw the cell text in various colors, draw images and lines, depending on data values.

My question is this:  What is the correct order to draw parts of the cell using the DataGridViewPaintParts?  Does it matter?  At present, the display is horrid - sometimes the cells are transparent (I can see what's underneath the application) and the text is scrambled.  A really good example of how to paint a cell would be great!

Thanks


C# Datagridview cell text compare

  

Hi

I have 2 datagridviews on a form and would like to know if it is possible to compare the text in the 2 views and highlight any differences?

For example:

DG1: Cell A1 Text > This is a test

DG2: Cell A1 Text > This iss some test

Is it therefore possible to highlight "iss" , "some" in red and show the corresponding dgv1 text in green?

I have done this with 2 richtextboxes and cannot work out how to do this with datagridview?

Any help with this is most welcome

Thanks in advance


DataGridView Combo Box Cell with sub menu

  

I need to create a column in the datagirdview that functions like a combo box with sub menus. As an example we have a cell that contains modes of transportation, and rather then a single list to select from the user can choose cars and then get a sub menu of car types or they can choose trucks and get a sub menu of trucks to choose from. 

Modes of Transportation
cars -> Volkswagon Rabbit, Volkwagon Dasher, Volkswagon Bug
truck -> Ford F150, Toyota etc . . 

I hope I have explained my problem accurately enough, if anyone has any insights or suggestions I would love to hear them.

-joe-

 

 


enabling the cursor in a specific cell within a datagridview

  

guys, i have an add record button in my datagridview application

i would like to enable the cursor on the first cell (in the last row) so the user would be able to enter some more information

i created an on click event, and can get and select the last row

but how do i set the cursor inside the specific cell ?

  Private Sub TestButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TestButton.Click
        Dim RowCount As Integer = Me.grdAccountTypes.RowCount - 1
        Me.grdAccountTypes.FirstDisplayedScrollingRowIndex = RowCount
        Me.grdAccountTypes.CurrentCell = grdAccountTypes.Rows(RowCount).Cells(0)
End SUb


unable to click on a cell using White UI Automation

  

ListView

 

 

listView = mainWindow.Get<ListView>(SearchCriteria

Dyanmically set background color of GridView cell

  

How can I make the background color of a GridView cell dependent on the boolean value of field?

 <asp:BoundField DataField="L_Enbld" HeaderText="ON" SortExpression="L_Enbld" >
 <ItemStyle BackColor="#CCFFCC" Font-Bold="True" Font-Names="Calibri" />
 </asp:BoundField>
 
Want to make red if L_Enbld is false, green if true.
 
Thank you


 


DataGrid Cell Background Color

  

Can someone show me how to change the background color of a DataGrid cell.  I have tried several examples and still having a time getting it to work.   I have a datagrid that is 10 by 11.  Each cell has a number (number will never change, just the color).  The number represents a particuliar alarm from a test stand.  I have to analyze the data from a data source and then set the background color. I am not binding to the data source.  I am really new to WPF and could use a complete example.  I do not have the toolkit install and I am using MS Visual C# express.  Thanks in advance.


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend