Hi
I have a grid with the source of a data table. One of the columns is an integer, unfortunately the data in the database has both zero and null instead of just one or the other. What this means is that I think the grid is happy to bring through the zero but the ultra combo (or value list as I tried that also) does not have a zero. It then displays a 0 in the grid, instead of a blank which is does do when the value in the database is Null.
I want to either update the field in the ultragrid so that if it is zero then display NULL, it should not update the underlying data source but just change the display to blank. Alternatively, do it in the ultracomboeditor.
I did find an item in the forums but the links pointed to a dead end, I think it may need a custom formatter but not sure if that is on the grid or the combo.
Here is a screenshot:
The top row has NULL in the database and the second row has 0 in the database.
The project I am doing is switching the UI from MS Access to Dot Net and I don't want to be having to update tables even though the very easiest fix would be to set any zeros to null in the database.
Thanks
Paul
Hi Paul,
Once the cell enters edit mode, it has to show the value so that the user can edit. There's really no way around that. But if you are only concerned about the display of the cell when it is not in edit mode, you could achieve this very easily by applying a custom Format to the column. Something like this:
this.ultraGrid1.DisplayLayout.Bands[0].Columns["EntityID"].Format = "g;g; ";
The Format is in 3 sections: positive, negative, and zero. So I used the General format for the first two and a single space character for the zero section.
Hi Andrew
You will just need a blank form with an ultragrid dropped on it then this is the form code, I want the EnttiyID in row 6 to show nothing like in row 7. I cannot update the database value to null so need to ensure any zeroes are represented as nothing, I would prefer no to have a blank option in the drop down as that will look poor.
public partial class Form1 : Form { DataTable gridTable; DataTable comboTable = new DataTable(); public Form1() { InitializeComponent(); CreateTableAndBindToGrid(); SetEntityIDToUltraCombo(); } private void CreateTableAndBindToGrid() { gridTable = new DataTable(); gridTable.Columns.Add("ID", typeof(int)); gridTable.Columns.Add("EntityID", typeof(int)); gridTable.Columns.Add("Description", typeof(String)); this.gridTable.Rows.Add(new object[] {1, 1, "Paul should be in dropdown" } ); this.gridTable.Rows.Add(new object[] {2, 2, "John should be in dropdown" }); this.gridTable.Rows.Add(new object[] {3, 3, "Heidi should be in dropdown" }); this.gridTable.Rows.Add(new object[] {4, 4, "Fred should be in dropdown" }); this.gridTable.Rows.Add(new object[] {5, 3, "Heidi should be in dropdown" }); this.gridTable.Rows.Add(new object[] {6, 0, "Drop down should be blank but is showing 0" }); this.gridTable.Rows.Add(new object[] {7, null, "Drop down is blank which is good" }); this.ultraGrid1.SetDataBinding(this.gridTable, "", true); } private void SetEntityIDToUltraCombo() { this.ultraGrid1.DisplayLayout.Bands[0].Columns["EntityID"].EditorComponent = new EntityDropDown(this.BindingContext); this.ultraGrid1.DisplayLayout.Bands[0].Columns["EntityID"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate; } } public class EntityDropDown : UltraComboEditor { private DataTable entitiesTable; public EntityDropDown(BindingContext bindingContext) { CreateEntitiesTable(); this.BindingContext = bindingContext; this.DataSource = entitiesTable; this.ValueMember = "ID"; this.AlwaysInEditMode = true; this.DisplayMember = "EntityName"; this.DropDownStyle = Infragistics.Win.DropDownStyle.DropDown; this.LimitToList = true; } private void CreateEntitiesTable() { this.entitiesTable = new DataTable(); entitiesTable.Columns.Add("ID", typeof(int)); entitiesTable.Columns.Add("EntityName", typeof(String)); entitiesTable.Rows.Add(new object[] { 1, "Paul" }); entitiesTable.Rows.Add(new object[] { 2, "John" }); entitiesTable.Rows.Add(new object[] { 3, "Heidi" }); entitiesTable.Rows.Add(new object[] { 4, "Fred" }); } }
Hello Paul,
I have done an initial investigation into this behavior you are seeing, and at the moment, I cannot seem to reproduce this behavior, and I believe I will need a bit more information from your end on how exactly your UltraComboEditor in the UltraGrid is set up, as there are many factors there.
With that said, being that your column is an integer, one thing you may want to ensure is that you are setting the Nullable property on that column so that it is nullable.
Would it be possible for you to please provide some sample code or an isolated sample project to demonstrate the behavior you are seeing so I may debug it and explain what may be happening further here?
Please let me know if you have any other questions or concerns on this matter.