Replies
Well I have answered it myself.
The cell value was an object so I did not see a problem with
object rowID = ….Cells[“ID”].Value
and then searching using
UltraGridRow[] rows = this.gridComponents.Grid.Rows.Where(s => s.Cells[“ID”].Value == rowID).ToArray()
nope, I had to convert my cell value to an int, alhtough i probably only had to do it in the search but
int rowId = COnvert.ToInt32(….Cells[“ID”].Value)
UltraGridRow[] rows = this.gridComponents.Grid.Rows.Where(s => Convert.ToInt32(s.Cells[“ID”].Value) == rowID).ToArray()
I suspect I could have left rowID as an object and done
UltraGridRow[] rows = this.gridComponents.Grid.Rows.Where(s => Convert.ToInt32(s.Cells[“ID”].Value) == Convert.ToInt32(rowID)).ToArray()
but I will just leave it be now
Maybe someone can explain why that was?
Thanks
Paul
Hi,
I think this has been posted to the wrong place as it is not related to my original question. Just thought I would let you know so you can repost if needed.
Regards
Paul
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 🙂
Thanks
Paul
Hi Mike,
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.
Thanks
Paul
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.
Thanks
Paul
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 Andrew,
Thanks this is what I am looking for. I have added code in the grid error handler that adds a new item to the combo editors bound table and then selects that items ID as the value for the cell which is the behavior I was looking for.
BindingContext has resolved the first issue without having to add controls to the forms control collection which is great too.
Thanks for your help,
Paul