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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

WpfDataGrid make cell background fill entire cell

Posted By:      Posted Date: September 17, 2010    Points: 0   Category :WPF
Hi!  I'm setting DataGridColumn.CellStyle to a background color and to a horizontal alignment. If I do not set the horizontal alignment the whole cell is filled with the background color but if i set the horizontal alignment the background color only is shown behind the text in the cell. I've seen some workarounds to this problem (http://stackoverflow.com/questions/1379902/setting-column-background-in-wpf-listview-gridview, setting the Margins on the DataGrid and the Cell margin) but it does not work for me. The background is still only shown behind the text   private void ApplyCellStyle(Style defaultColumnStyle, DataGridColumn dataGridColumn, Color backgroundColor, HorizontalAlignment horizontalAlignment) { var style = new Style(typeof(DataGridCell), defaultColumnStyle); var backgroundPropertySetter = new Setter { Property = Control.BackgroundProperty, Value = new SolidColorBrush(backgroundColor) }; var horizontalAlignmentPropertySetter = new Setter { Property = FrameworkElement.HorizontalAlignmentProperty, Value = horizontalAlignment }; style.Setters.Add(horizontalAlignmentPropertySetter); style.Setters.Add(backgroundPropertySetter); dataGridColumn.CellStyle = style; }   Does anyone know a solution to this problem?    Regards, Lina

View Complete Post

More Related Resource Links

Enhance SSAS so that a calculation returns multiple cells at once (Excel fill not a single cell but

I wonder if somebody can help me with the following question. I would like to create an enhancement to SSAS in a way so that one can pass in multiple values, run a calculation and in return retrieves not one but multiple cell results at the same time e.g. retSet = functionABC(inSET) where inSet is somthing like 5 4 3 6 7 3 4 4 AND retSet is 4 6 7 8 9 3 4 4 All my calculated members in MDX return a single value BUT I need to have a calculation that if called returns multiple results (a set) at once and in a way so that Excel will properly pick up on it and consequently fills multiple cells in the Pivot table. Is that possible at all and if so how? I would not mind to write a little CLR assembly to enhance the SSAS but don't know how to pass the results back. Any ideas are highly appreciated. Dirk

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?

How to make a connection between a word in the cell (href)? and a rule of the same or another table

 HelloHow to make a connection between a word in the cell (href)? and a rule of the same or another table with sql. Is there also finished editors?

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



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.


How to make a cell editable in gridview?


I was trying to create a gridview which should allow to edit a perticular cell on clicking on it. But is not working as expected. Here is my code. Can anyone tell whats the issue with this.

<Window x:Class="Window1"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="Window1" Height="279" Width="672">

        <Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}" >
            <Setter Property="Background" Value="#00ffffff" />
            <Setter Property="BorderBrush" Value="#00ffffff" />
            <Setter Property="Acce

How can a fill a cell in a gridview in a windowsform?


I have a gridview in a windowsform.
There are 4 columns (A, B, C and D).
I column D is a combobox.
How can I fill this combobox at form_load with the following data: --> 

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" />
Want to make red if L_Enbld is false, green if true.
Thank you


How do I make a DataGrid fire an event when a cell is changed?


I tried to figure this out a while ago but gave up - now I'm in a situation where I need to try again.

I have a DataGrid (using .NET 4) and I'm trying to fire an event when a cell is changed.  However, I cannot generate any events until a different row is selected.  So, for example, I have a datagrid with a checkbox column and I want an event to occur when the user changes one of the checkboxes.  As it is right now, I can't generate an event until the user selects another row after changing the checkbox.

I've tried every type of event I can find - RowEditEnding, CellEditEnding, CurrentCellChanged, MouseLeftButtonUp, MouseLeftButtonDown, etc.  None is ever fired when the checkbox is changed - they don't fire until another row is selected.

So, I can click away on a checkbox hundreds of times and no events will be generated.  As soon as I change rows, though, the events occur.

Any help with this one?  This is such an elementary problem I'm sure there's something basic I'm missing.  Suffice it to say, I don't use WPF very often :)  I've seen the same question asked elsewhere and there are supposed answers but they are extremely complicated and I can't get them to work.

Thanks in advance,


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.

How do I make a cell in a listview funciton to click as a url


 I have a listvieiw with url's in some of the cells.  When I click on them they do nothing.  I formated the cells to be "hyperlinks" but still nothing.

Any ideas?

how to make a css style background image be linked to an image in the resource file


hey guy, i need help in a very troubling matter. I want to make a textbox with a specific style, within this style a set of images as background parts, how can i attach these images to the custom control as whenever i take the .dll file and add it to the toolbar the images do not appear. So i tried to make them as resource files and their property as embedded in .resx file, so how to make the css style background image url to be linked to any of those image.

thanks in advance

Passing Data to a Cell in Excel



I have a webpage that is created in Visual Studio 2008 and programmed in C#.

I have a web form that prompts the user to enter a value into a text box.  For now, I do not have any validation on that field (I will be adding that later).

I need to pass the value that the user has entered to cell C1 of the excel spreadsheet (user_info.xls).

I understand that using excel is not ideal, but unforutnately need to try to make this work with the excel spreadsheet.

I do not have any code for this yet, because I honestly do not know how to begin.

The action of poulating the excel spreadsheet will be intialized from the On Click event of a Submit button.

Any suggestions would be much appreciated.

Thank you in advance for your assistance,


How can i add a textbox into a GridView Cell dynamically and how can i retrieve entred data

Hey, i think that the the subject can explain what i need, it's about adding a TextBox control with the code behind into a GridView, and also about how can i retrieve entered data after submitting, im using C#,Thanks.

I need to set the value of a gridview cell during update.

Hi,  I've been reading the posts here and I'm not finding, or maybe just not understanding, the answer I need so here's my problem. I have a small gridview and the update works very well. The issue is I need to have one of the fields set to a value from my code either when the record is open for undating or when the update runs.  Here is my gridview and the datasource info:<asp:GridView ID="GridViewItemLog" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" CellPadding="3" DataKeyNames="LogID" DataSourceID="SqlDataSourceItemLogEntries" GridLines="Vertical" onrowdatabound="GridViewItemLog_RowDataBound" onrowupdating="GridViewItemLog_RowUpdating" onrowediting="GridViewItemLog_RowEditing"><AlternatingRowStyle BackColor="Gainsboro" /><Columns><asp:CommandField ButtonType="Image" CancelImageUrl="~/Resources/StopSmall.png" EditImageUrl="~/Resources/EditSmall.png" ShowEditButton="True" UpdateImageUrl="~/Resources/Save.png" /><asp:Boun

some of the cell value cant read from Excel

Hi all, Im reading some data from the excel file, using below code objBusy = new BusinessLogic();                string strFileName = FileUpload1.PostedFile.FileName;                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;";                OleDbConnection objConn = new OleDbConnection(connectionString);                objConn.Open();                String strConString = "SELECT * FROM [Product1$]";                //where date = CDate('" + DateTime.Today.ToShortDateString() + "')";                OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn);                // Create new OleDbDataAdapter that is used to bui

report count on a cell which come from a subrepot

Hi, Ive my main report and a subreport which is working well, but I need to count this value, how can I manage this? Or maybe I do need to add the subreport with less parameters? Thanks

Gradient Colors in table cell

How to fill the gradient colors in table cells?
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