By default, in the Property Builder for GridView, the defaults are:
Header Text Alignment = Middle Center
Text Alignment = Middle Left.
This means that EVERY time I create a new grid, I have to remember to make them both the same.
Why make them different? It makes the grid look rubbish whenthe defaults are used.
In this particular scenario, the RadDropDownListEditor element inside the RadComboBoxColumn cell contains an empty string item. So when we try to clear the value of the cell and leave it empty, the internal logic will return the last selected valid value. The following code demonstrate a simple example:
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("codice", typeof(string));
dt.Columns.Add("nome", typeof(string));
dt.Rows.Add(0, "", "");
dt.Rows.Add(1, "I622", "Seravezza");
dt.Rows.Add(2, "G628", "Pietrasanta");
dt.Rows.Add(3, "L833", "Viareggio");
The first row in the DataTable which the RadGridView contains an empty value. If for example, the second row is selected and we use Backspace/Delete to clear the text and move to another cell. The selected item won't be changed. The cell value won't be cleared. To workaround this we could avoid using empty strings. We could use space or some other symbol to allow the user to clear the value from the drop-down popup.
dt.Rows.Add(0, "", "-");
OR
dt.Rows.Add(0, "", " ");
GridViewCellInfo offers Style property which allows you to customize the style for the cells defined at the data cell's level: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/style-property
This functionality should work for the header cells as well like this:
GridViewCellInfo cell = this.radGridView1.MasterView.TableHeaderRow.Cells[0];
cell.Style.CustomizeFill = true;
cell.Style.GradientStyle = GradientStyles.Solid;
cell.Style.BackColor = System.Drawing.Color.FromArgb(162, 215, 255);
When you use var, object is assumed. Of course, the object contains a GridViewCellInfo, but you have to cast it first to use one of its members.
The goal is to prevent unnecessary casts.
When the columns are auto-generated, the way to modify the columns is to use the Columns collection. We could expose an event that will be called when the columns are auto-generating. From the event arguments, we could get the newly created column and replace with if needed or modify it. Similar to the CreateRow event of the control.
Please refer to the below gif file. You will notice that the drop row line is shown only when dropping in the same grip but not when dropping on another grid:
Workaround: use the project in the following forum post: https://www.telerik.com/forums/preview-drop---drag-drop-between-gridview#5477699
Eery time I use the GridView, I have to remember to un-select the last item in the list.
This is almost always to wrong thing to be selected - so why select it by default?
..and the way to swith this 'feaure' off isn't obvious - I always have to look it up....RadGridView1.CurrentRow = Nothing
With releasing .NET 6, there are TimeOnly and DateOnly types which would be more appropriate for managing such values:
https://devblogs.microsoft.com/dotnet/date-time-and-time-zone-enhancements-in-net-6/
It would be good to add support for these types in GridViewDateTimeView.
Currently, the following code gives an exception when entering edit mode:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("DateOnly", typeof(DateOnly));
dt.Rows.Add(new DateOnly(2022,3,3));
this.radGridView1.AutoGenerateColumns = false;
GridViewDateTimeColumn dateColumn = new GridViewDateTimeColumn();
dateColumn.FieldName = "DateOnly";
this.radGridView1.Columns.Add(dateColumn);
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
Workaround: you can use the following custom TypeConverter:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("DateOnly", typeof(DateOnly));
dt.Rows.Add(new DateOnly(2022,3,3));
this.radGridView1.AutoGenerateColumns = false;
GridViewDateTimeColumn dateColumn = new GridViewDateTimeColumn();
dateColumn.DataType = typeof(DateTime);
dateColumn.FieldName = "DateOnly";
dateColumn.Format = DateTimePickerFormat.Custom;
dateColumn.CustomFormat = "dd/MM/yyyy";
dateColumn.FormatString = "{0:dd/MM/yyyy}";
dateColumn.DataTypeConverter = new DateOnlyConverter();
this.radGridView1.Columns.Add(dateColumn);
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
public class DateOnlyConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(DateTime);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is DateOnly && destinationType == typeof(DateTime))
{
DateOnly date = (DateOnly)value;
return new DateTime(date.Year, date.Month, date.Day);
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(DateTime) ;
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is DateTime)
{
DateTime date = (DateTime)value;
return new DateOnly(date.Year, date.Month, date.Day);
}
return base.ConvertFrom(context, culture, value);
}
}
Hi. it was great to see the option "ImageOnly", for columns of small width, where only the image is placed in the header, and the "HederText" property was set, for the correct display of the grouping field
GridViewDataColumn column;
column.HeaderText = "Счет";
column.HeaderImage = ...; // some img
column.TextImageRelation = TextImageRelation.Overlay;
GridViewDataColumn column;
column.HeaderText = "";
column.HeaderImage = ...; // some img
column.TextImageRelation = TextImageRelation.Overlay;
it’s impossible to choose one thing, either an ugly header, or a grouping without a description
Use the following code snippet:
GridViewDateTimeColumn orderDate = this.radGridView1.Columns["OrderDate"] as GridViewDateTimeColumn;
orderDate.Format = DateTimePickerFormat.Custom;
orderDate.CustomFormat = "dd-MM-yyyy";
orderDate.FormatString = "{0:dd-MM-yyyy}";
GridViewDateTimeColumn shippedDate = this.radGridView1.Columns["ShippedDate"] as GridViewDateTimeColumn;
shippedDate.Format = DateTimePickerFormat.Custom;
shippedDate.CustomFormat = "dd-MM-yyyy";
shippedDate.FormatString = "{0:dd-MM-yyyy}";
When the grid is grouped by a column with a specific format, it should be taken in consideration by the group row as well.
Dear Support team,
Our Application issue: While running application in assistive mode and having a grid with large number of columns, Narrator/JAWS starts reading each Column Value as "DbNull"
while User is Tabbing through selected Row. (Please see attach Video for better understanding.)
I also created a sample Program:
1. Build Win Form app having a RadGridView. [Sample Attached in 1514161]
2. Start Win 10 Narrator App
3. Run App from Step #1 [Note: Please do not Resize Main Form yet]
4. Start Tabbing from Grid selected Row. Narrator does not read/speak Cell Values.
5. Now Close & Run Application again and Maximize Window. Repeat Step #4. Narrator reads/speak Cell Values as expected.
It seems reads all values fine until they are visible, and once you continue tabbing and horizontal scrolling happens and then stops reading.
Please advice. A Fix for it would be a great help!
Looking forward to hear back!
Thanks and Regards,
Vivek
Sr. .Net Developer