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
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.
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" }); } }
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 Mike,
Thanks, I will leave it as is and hope that I don't find any others instances that are harder to sort out. If so then I think the additional column should suffice and if not, well.......expect more questioning :)
That sounds like a good solution. You could also do it on the client side by simply putting some kind of layer in between the grid and the actual data. For example, you could get the data from your database into a DataTable/DataSet, but then use UltraDataSource in on-demand mode as a sort've intermediary. That would be a lot of code, though. Another option would be to simply hide the "real" column of data in the grid and then add an additional unbound column to display to the user. And then you could control the contents of that column in code by translating "0" into null and vice versa. This would be a lot less code, but it might be a bit tedious if you have to do this for a lot of columns dynamically.
It's not the answer I was hoping for. I am switching a MS Access UI to dotnet and in MSAccess the zeros and nulls show blank so wanted to replicate this.
I have changed to a stored procedure that returns a null instead for the SELECT command of the dataadapter and that seems to work and I didn't have to change the existing data so will go this route when necessary.