Format UltragridRow Cells - vb.net

I need to format the cell of an UltraGrid.
Like: Making the cell to format a DateTime.
I have done for a column,
UltraGridColumn.Format = "d"
likewise is there any option to format individual cells?
UltraGridRow.Cells("abc")= ?
Note: Using the Infragistics version 12.1

The trick to force the UltraGrid to use different editors for cells in the same column is based on a set of programming objects and patterns offered by the infrastructure of the control.
The first thing is to consider is the InitializeRow event. This event is called for each row when you set the initial DataSource of the grid or when you change something in the underlying DataSource. You can differentiate between the two situations thanks to the e.Reinitialize flag. If it is false, then the whole datasource is applied to the grid, if it is true then only a subset of rows are reinitialized usually because the user has edited the cell or the code has changed a value in the datasource.
The second thing to consider is the Editor property present in every UltraGridCell or UltraGridColumn. It is an object that is built automatically by the UltraGrid to allow the cell editing. The UltraGrid code set this object based on the datatype of the column and, obviously, sets the same editor for every cell of the column. You could set your own editor at the column level (usually in the InitializeLayout event) or on cell by cell basis looking at your formatting rule.
Let's try an example (Big parts of this is taken from the example code suggested in its comments by Alhalama)
Suppose you have a DataTable with only two columns:
First column is called CONDITION and contains a string. This string is my formatting requirement.
The second column is called DATEINFO and contains the dates that should be formatted differently accordingly to the value in the column CONDITION.
So if CONDITION = 'TEST1' then the DATEINFO cell is formatted with Day/Month/Year pattern, if the CONDITION='TEST2' then the DATEINFO cell should be formatted with Hour/Minute/Seconds.
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
{
if (e.ReInitialize == false)
{
DefaultEditorOwnerSettings editorSettings;
DateTimeEditor datetime_editor;
string condition = e.Row.GetCellValue("Condition").ToString();
switch (condition)
{
case "TEST1":
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "mm/dd/yyyy";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
break;
case "TEST2":
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "hh:mm:ss";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
break;
}
}
}

Related

How do you format a datagridview column that is connected to a datasource?

Current screenshot:
I'd like to format the displayed value in the datagridview in the picture to two decimals, i wanted to make the change at display so i still have my orignal values untouched.
I've tried it placing the format in code
before, (At Form's New Sub)
after assigning the datagridview's datasource, (at Form's New Sub)
and also placing it in the designer, (datagridviewtextboxcolumn.defaultcellstyle)
still the values in the datagridview didnt change
You can put this in form load:
dataGridView.Columns["Total"].DefaultCellStyle.Format = "N2";
OR
private void dataGridView_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == indexOfColumn)
{
e.CellStyle.Format = "N2";
}
}

Gridcontrol edit/update mandatory fields different colour

I'm just wondering how can I change background colour of mandatory fields while adding new row.
So for example name and surname would be red (mandatory) and phone would be default white.
Thank you
Patryk
The best way to do this is through the grid's designer -- in most cases you don't need to write any code to accomplish this.
If you go to the Grid View designer, select the menu item "Appearance" and "Format Rules:"
From here, you can add a format condition by clicking the plus icon:
Under "Column," pick the column you want the format condition to apply to.
Under "Rule," pick an appropriate rule -- based on what you described, you probably want "Format Based on a Value," FormatConditionRuleValue.
On the "Rule" tab of this same dialog, you can set your "Value1" and "Condition" properties accordingly, for example Value1 = 15, Condition = "equals."
The "Appearance" property will let you determine how to format the cell based on these conditions.
The beauty of this approach is it's all designer-based code, and it's very easy to customize. The logic behind the formatting is also very transparent. The format conditions have been expanded to let you evaluate expressions as well, meaning you can create your own formulas using other column values and functions.
If all else fails, you can use the RowCellStyle event, but my first attempt would always to be to use the designer tools.
You can use an event gvView_CustomDrawCell and set background color only if the line is in state that you need (Added, Detached ...)
private void gvView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column != null && (e.Column.Name == bgcName.Name || e.Column.Name == bgcSureName.Name))
{
DataRow focusedRow = gvView.GetDataRow(e.RowHandle);
if (focusedRow != null)
{
if (focusedRow.RowState == DataRowState.Added)
{
e.Appearance.BackColor = Color.FromArgb(80, 10, 30, 200);
}
}
}
}
asd

Standard formatting Vs Custom formatting in UltragridCells

I'm trying to format a Ultragridcell using the following code and it works fine.
//Code
DefaultEditorOwnerSettings editorSettings;
DateTimeEditor datetime_editor;
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "mm/dd/yyyy";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
But when I try to format like the below code, it fails.
//Code
DefaultEditorOwnerSettings editorSettings;
DateTimeEditor datetime_editor;
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "D";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
Is that only the custom formatting that too only limited types works with the cell or i'm wrong somewhere.
Need an advice on this.
It seems that you think that MaskInput property supports all the formatting functionality provided by Composite Formatting, but I don't think that it is true.
The formatting available for MaskInput as far as I know are limited to only these provided by the UltraGrid Designer.
Using the UltraGrid Designer (right click on the UltraGrid control, select UltraGrid Designer) click on the Data Schema and define a data schema in which one of the columns will be a DateTime column. Then go to the Bands and Column Settings node, select columns and then the column defined as DateTime. In the properties window you can find the MaskInput property and its allowed values. You could try to experiment with the predefined masks and check if there is one that fits your requirements.
As I have said this is what I suppose to be true. I don't know if there is another advanced mode to set these properties at design time or at Runtime. If, someone from Infragistics, wants to add something to this answer would be welcome

How to change font color of a dojo DataGrid row after a cell has been edited

I want to change the font color of a row after a cell in that row has been edited and set to a certain value.
myStore is the dojo.data.ItemFileWriteStore associated to the dojox.grid.DataGrid dataGrid.
I have written this:
myStore.onSet = function(item, attribute, oldValue, newValue) {
if (item.myField == myValue) {
var index = dataGrid.selection.selectedIndex;
dojo.style(dataGrid.getRowNode(index), "color" , "red");
}
}
but unfortunately this doesn't make any effect...
UPDATE: I added the following style property: "backgroundColor" : "red". Well, the background color of the row changes to red, but when the mouse moves away from the row, the color changes back to the default! It might be that some default event handlers restore the default styles...
The dojo.style line works if you call it by itself. Either your function isn't being called at all, the if's condition false or there is no row selected and you are getting an invalid number for the index. (You can put some console.logs there to check)

How to hide the column header for a Devexpress GridLookUpEdit?

I currently have a DevExpress GridControl where one of the columns have a GridLookUpEdit assigned under ColumnEdit. Yet when I run there is a column name (the display member) that shows up.
I know with a LookUpEdit you can set the column headers to invisible with lookupedit.Properties.ShowHeader = False but I have no clue how to make it invisible for the GridLookUpEdit.
Use:
lookupedit.Properties.View.OptionsView.ShowColumnHeaders = False
Use the following code to hide a column:
gridLookUpEdit1.Properties.View.Columns("SomeFieldName").Visible = false
What you do is run the property editor, go to columns and select the column that your lookupedit is assigned to. Then expand your column edit, then the view within, then the OptionsView. Then set ShowColumnHeaders to false. This will set all of the column headers within the lookupedit to false.
For devexpress 18.2.8
I'm using the following code to hide a column:
using (DataTable dt = rst.ResultSet.Tables[0].Copy())
{
dt.Columns["Unit_ID"].ColumnMapping = MappingType.Hidden;
ddlUnitOfMeasurement.Properties.DataSource = dt.DefaultView;
ddlUnitOfMeasurement.Properties.ValueMember = "Unit_ID";
ddlUnitOfMeasurement.Properties.DisplayMember = "Unit_Name";
}