These should be fairly easy questions:
1. I would like to draw a blue border around any cell that's been changed since the last update...what's the best way to do this?
2. I would like to change the forground color of the text in a cell if the first character is a ! - for example to indicate a phone number is disconnected !(123) 456-7890 would display in red
3. I have a fairly simple table with one column being a "status" this is an integer that relates to a status table (1=Active, 2=Inactive, 3=Dead). I'd like that column to be a combobox bound to column 1 of the status table, but displaying column 2.
4. Do I need to manually call a save function for the grid? I assume so, does it have a way I can determine if data is changed (ie OnClose() ...if ultrgrid1.DataIsDirty() then save...
Thanks for your help on this. This is my first adventure with ultragrid (having come from years and years of doinng stuff myself with ado in C++)
Peter
Hi Peter,
howudodat said:1. I would like to draw a blue border around any cell that's been changed since the last update...what's the best way to do this?
Drawing a border around a cell is not easy. Most cells in the grid only draw one or two sides of their own borders. If every cell drew all 4 sides, there would be double-thick borders between each cell. So each cell only draws one or 2 and relies on the adjacent cells to draw their own borders to present a nicer look.
If you want to draw a border around a cell, then you could have to do this using a DrawFilter so that you could draw all 4 sides.
I recommend using some other indicator - like maybe the BackColor of the cell, or maybe make the font bold. That would be a lot easier and you could do it using the cell's Appearance.
howudodat said:2. I would like to change the forground color of the text in a cell if the first character is a ! - for example to indicate a phone number is disconnected !(123) 456-7890 would display in red
You could do this using the InitializeRow event. There are samples of this sort of thing all over the place - like in the documentation and in the Samples Explorer. If you are concerned about doing this in the most efficient way, you should check out the WinGrid Performance Guide.
howudodat said:3. I have a fairly simple table with one column being a "status" this is an integer that relates to a status table (1=Active, 2=Inactive, 3=Dead). I'd like that column to be a combobox bound to column 1 of the status table, but displaying column 2.
HOWTO:What is the best way to place a DropDown list in a grid cell?
howudodat said:4. Do I need to manually call a save function for the grid? I assume so, does it have a way I can determine if data is changed (ie OnClose() ...if ultrgrid1.DataIsDirty() then save...
The grid only saves the data to it's DataSource. You might have to call the grid.UpdateData method to make sure the data is committed from the grid to the data source. If you are talking about updating the data from your data source to the back end (database), then the grid is not involved in that process at all. How you do that depends on your data source, and you should consult Microsoft's documentation.
1. Ok, I am now setting the background color using InitializeRow event. Is there a way to tell if just one cell changed? Right now I do:
if (e.ReInitialize) e.Row.CellAppearance.BackColor = System.Drawing.Color.LightSteelBlue;
but that sets the whole row
2. Again I am using InitilializeRow. Here is how I set it. Is this the right way? Is there an event wizard?
this.ultraGrid1.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.ultraGrid1_InitializeRow);
3. HOWTO solved it!. However quick followup question. I now have 2 controls just placed orphaned on my form that the grid uses as editors. A CheckBox control, and ultrawindropdown. Both are set to hidden and are covered up by the ultragrid. However I can see how this could really clutter up a form in design time. Am I missing something here? I can't see any other way other than hand coding.
4. Ok, so is there an event that I can use to set a dirty Boolean, or is there a built in dirty flag?
howudodat said: 1. Ok, I am now setting the background color using InitializeRow event. Is there a way to tell if just one cell changed? Right now I do: if (e.ReInitialize) e.Row.CellAppearance.BackColor = System.Drawing.Color.LightSteelBlue; but that sets the whole row
You are setting the CellApearance on the Row. That affects all cells in the row. To affect an individual cell, you need to do something like this:
e.Row.Cells[columnKey].Appearance.BackColor = System.Drawing.Color.LightSteelBlue;
Also, I don't think you want to use e.ReInitialize here. The InitializeRow event fires quite often and this flag will be true every time but the first time for each row. This flag does not necessarily indicate anything about the state of the row except that is it being initialized again.
howudodat said: 2. Again I am using InitilializeRow. Here is how I set it. Is this the right way? Is there an event wizard? this.ultraGrid1.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.ultraGrid1_InitializeRow);
The Visual Studio property grid provides a list of events and creates event handlers for you for any control. This is nothing to do with the Infragistics controls. You should consult the Visual Studio documentation for more information.
howudodat said:3. HOWTO solved it!. However quick followup question. I now have 2 controls just placed orphaned on my form that the grid uses as editors. A CheckBox control, and ultrawindropdown. Both are set to hidden and are covered up by the ultragrid. However I can see how this could really clutter up a form in design time. Am I missing something here? I can't see any other way other than hand coding.
You could create the controls in code. Or just create editors instead of controls. Or, for most cases, you can probably just set the Style property on the column, rather than using an editor. It depends on the needs of your application.
Another option that I have used is to use an UltraWinTab control and set it's Style to Wizard. This gives you multiple tabs at design-time and run-time, but there is no UI at run-time.
howudodat said:4. Ok, so is there an event that I can use to set a dirty Boolean, or is there a built in dirty flag?
I'm afraid I do not understand your question.
1. Perhaps I should re-ask this question: How can I change the background color of a cell that has been modified? How can I tell which cell changed?
4. Is there a dirty flag for the grid...for example: if (ultragrid1.IsDataModifie()) { Prompt for save }
1. The UltraGridCell class exposes a DataChanged property, which (like the same property on UltraGridRow) returns whether the cell has pending changes.
4. No, you would have to iterate the Rows collection(s) and check the DataChanged property on each UltraGridRow.
After spending quite soem time looking at all the functions for the grid, and extrapolating from the documentation on the webgrid (where is the docs for the winforms grid???) here is what I did...which is what I asked for in the first post:
private boolean bGridIsModified;private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){ this.ultraGrid1.AfterCellUpdate += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_UpdateCellEvent); bGridIsModified = false;}
public void ultraGrid1_UpdateCellEvent(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e){ e.Cell.Appearance.BackColor = System.Drawing.Color.LightSteelBlue; bGridIsModified = true; }
Now 2 days later...that wasn't so hard (he says sarcastically)