| void _grid_CellFormatting(object sender, CellFormattingEventArgs e) |
| { |
| if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement)) |
| { |
| GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo; |
| if (column.FieldName == "Minutes") |
| { |
| int minutes = (int)e.CellElement.RowInfo.Cells["Minutes"].Value; |
| TimeSpan ts = TimeSpan.FromMinutes(minutes); |
| e.CellElement.Text = string.Format("{0:00}:{1:00}", ts.Hours, ts.Minutes); |
| void _grid_CellFormatting(object sender, CellFormattingEventArgs e) |
| { |
| if (e.CellElement.ColumnInfo is GridViewDataColumn && (!(e.CellElement.RowInfo is GridViewFilteringRowInfo)) && |
| (!(e.CellElement.RowElement is GridTableHeaderRowElement))) |
| { |
| GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo; |
| if (column.FieldName == "Minutes") |
| { |
| if(e.CellElement.RowInfo.Cells["Minutes"].Value!=null) |
| { |
| int minutes = (int)e.CellElement.RowInfo.Cells["Minutes"].Value; |
| TimeSpan ts = TimeSpan.FromMinutes(minutes); |
I have an image cell where the image is added conditionally using CellFormatting:
Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
Try
If e.CellElement.ColumnIndex = 1 Then
If CType(e.CellElement.RowInfo.Cells("type").Value = 0, Decimal) Then
e.CellElement.Image = Me.ImageList1.Images(0)
ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 1, Decimal) Then
e.CellElement.Image = Me.ImageList1.Images(1)
ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 2, Decimal) Then
e.CellElement.Image = Me.ImageList1.Images(2)
ElseIf CType(e.CellElement.RowInfo.Cells("type").Value = 3, Decimal) Then
e.CellElement.Image = Me.ImageList1.Images(3)
Else
e.CellElement.Image = Me.ImageList1.Images(3)
End If
End If
e.CellElement.DrawFill = True
If Not IsDBNull(e.CellElement.RowInfo.Cells("Status").Value) Then
e.CellElement.DrawFill = True
Select Case (e.CellElement.RowInfo.Cells("Status").Value)
Case 23
e.CellElement.BackColor = Color.Pink
Case 24
e.CellElement.BackColor = Color.Chartreuse
Case 25
e.CellElement.BackColor = Color.Yellow
Case 26
e.CellElement.BackColor = Color.SkyBlue
Case 27
e.CellElement.BackColor = Color.LightCyan
Case 28
e.CellElement.BackColor = Color.Crimson
Case 29
e.CellElement.BackColor = Color.Blue
Case 30
e.CellElement.BackColor = Color.Red
Case Else
End Select
Else
e.CellElement.BackColor = Color.WhiteSmoke
End If
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
This colours the whole row I only want the background behind the image to have the colour applied how do I do this?
Regards
Joe
| private void SetupForm() |
| { |
| try |
| { |
| // Add the events |
| this.radGridViewExceptions.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridViewExceptions_ViewCellFormatting); |
| this.radGridViewExceptions.DataSource = m_objExceptions.GetLast30DaysExceptions(); |
| // Wrapping text only seems to work correctly if this is not commented out // and I do not set the column widths below // this.radGridViewExceptions.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; |
| this.radGridViewExceptions.MasterGridViewTemplate.AllowColumnReorder = false; |
| this.radGridViewExceptions.MasterGridViewTemplate.AllowColumnResize = false; |
| this.radGridViewExceptions.AutoSizeRows = true; |
| // Format the columns |
| foreach (GridViewColumn column in radGridViewExceptions.Columns) |
| { |
| switch (column.HeaderText) |
| { |
| case "When_Occured": |
| case "Description": |
| column.Width = 200; |
| break; |
| case "App_Assembly": |
| column.Width = 120; |
| break; |
| case "App_Assembly_Version": |
| column.Width = 150; |
| break; |
| default: |
| column.Width = 100; |
| break; |
| } |
| column.WrapText = true; //radCheckBoxShowFullText.Checked; |
| } |
| m_bFormLoaded = true; |
| } |
| catch (Exception ex) |
| { |
| ShowException(ex); |
| m_bFormLoaded = false; |
| } |
| } |
| int visualRowsCount = this.radGridView1.GridElement.VisualRows.Count; |
| this.radGridView1.GridElement.ScrollToRow(indexToScroll - visualRowsCount + 3); |
| this.gridDocs.MasterGridViewTemplate.Columns.Clear(); |
| this.gridDocs.MasterGridViewTemplate.DataSource = docs; |
| namespace RadComboTest |
| { |
| partial class Form1 |
| { |
| /// <summary> |
| /// Required designer variable. |
| /// </summary> |
| private System.ComponentModel.IContainer components = null; |
| /// <summary> |
| /// Clean up any resources being used. |
| /// </summary> |
| /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
| protected override void Dispose(bool disposing) |
| { |
| if (disposing && (components != null)) |
| { |
| components.Dispose(); |
| } |
| base.Dispose(disposing); |
| } |
| #region Windows Form Designer generated code |
| /// <summary> |
| /// Required method for Designer support - do not modify |
| /// the contents of this method with the code editor. |
| /// </summary> |
| private void InitializeComponent() |
| { |
| this.radComboBox1 = new Telerik.WinControls.UI.RadComboBox(); |
| ((System.ComponentModel.ISupportInitialize)(this.radComboBox1)).BeginInit(); |
| this.SuspendLayout(); |
| // |
| // radComboBox1 |
| // |
| this.radComboBox1.Location = new System.Drawing.Point(12, 12); |
| this.radComboBox1.Name = "radComboBox1"; |
| // |
| // |
| // |
| this.radComboBox1.RootElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren; |
| this.radComboBox1.Size = new System.Drawing.Size(260, 20); |
| this.radComboBox1.TabIndex = 0; |
| this.radComboBox1.Text = "radComboBox1"; |
| // |
| // Form1 |
| // |
| this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
| this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
| this.ClientSize = new System.Drawing.Size(284, 264); |
| this.Controls.Add(this.radComboBox1); |
| this.Name = "Form1"; |
| this.Text = "Form1"; |
| ((System.ComponentModel.ISupportInitialize)(this.radComboBox1)).EndInit(); |
| this.ResumeLayout(false); |
| this.PerformLayout(); |
| } |
| #endregion |
| private Telerik.WinControls.UI.RadComboBox radComboBox1; |
| } |
| } |
| using System; |
| using System.Diagnostics; |
| using System.Windows.Forms; |
| using Telerik.WinControls.UI; |
| namespace RadComboTest |
| { |
| public partial class Form1 : Form |
| { |
| public Form1() |
| { |
| InitializeComponent(); |
| radComboBox1.Items.Add(new RadComboBoxItem("Item1", 1)); |
| radComboBox1.Items.Add(new RadComboBoxItem("Item2", 2)); |
| radComboBox1.Items.Add(new RadComboBoxItem("Item3", 3)); |
| radComboBox1.SelectedValueChanged += new EventHandler(radComboBox1_SelectedValueChanged); |
| } |
| void radComboBox1_SelectedValueChanged(object sender, EventArgs e) |
| { |
| Debug.Fail("radComboBox1_SelectedValueChanged"); |
| } |
| } |
| } |
private
void Form_Load(object sender, EventArgs e)
{
this.radTextBox.Focus();
}
The cursor does not get set onto the radTextBox. What needs to be done here?
Thanks!
Jeremy