Hi,
I am trying to figure out a way to do the follow:
I have an UltraGrid with 1 hidden primary key column and 5 visible data columns.
Column 1 and 2 are drop down lists.Column 3 is a dynamic cell.Column 4 is a text fieldColumn 5 is a drop down list.
I have an ultra data source, a DataSet, and DataTable. The DataTable matches the ultraDataSouce:string, string, object, double, string. I can data bind the Columns 1, 2, 4, and 5. But column 3 is the tricky one.
When the user makes a selection on column 2, the cellListSelected event is fired, and its event handler should analyze the selection, and make column 3 a text field, edit field with an edit button, default text with an edit field and edit button, or a drop down list for other selections.
My question is, how does data binding work with such a situation? Is it even possible?
Thanks
I'm not quite sure what you mean by "dynamic cell", but it sounds like you want the cell to handle different data types.
If that's the case, then it sounds like you are on the right track using object as the data type for that column.
Beyond that, it seems like you will need to assign a different Editor/EditorComponent to the cell in column 3 based on the value in Column 2. You can't use just the CellListSelect event for this, since this event will only fire when the user selects an item from the list. This will not account for the case when the grid displays the first time, for example.
So I would recommend using the InitializeRow event, and maybe also AfterCellUpdate.
In InitializeRow, you examine the value of Column 2 and then assign an Editor or EditorComponent to the cell in Column 3. For just a normal text field, you would use an UltraTextEditor. For a text field with a button, you would use a different UltraTextEditor control that has an EditorButton added to it's ButtonsRight collection. For a dropdown list, you have to use UltraComboEditor - or just reset the editor on the cell and use a ValueList.
Mike,
Thanks for the response. And yes, the "dynamic cell" refers to a cell whose data type, or control is different depending on the value selected in drop down list in column 2.
As for the data binding, since the DataTable has myCustomDataClass object, I simply do a look up on the row based on the Primary Key, update the myCustomDataClass object and its value that appears on the grid.
Data binding this way is fine I guess? But should I be creating different data sources for each different control? Say, one for the text field, one for the editor, and one for the combobox/drop down list?
You mentioned using the ComboBox for a DropDownList, but cant i just set the Style to Style.DropDownList?
DCSteve said:Data binding this way is fine I guess? But should I be creating different data sources for each different control? Say, one for the text field, one for the editor, and one for the combobox/drop down list?
Okay, you lost me here. If the field in your data table is some custom object, then that's fine. You just override it's ToString method to return whatever you want the user to see on the screen.
I'm not sure what you mean about different data sources for each different control. What other controls are you referring to? I thought you were just using a single grid here.
DCSteve said:You mentioned using the ComboBox for a DropDownList, but cant i just set the Style to Style.DropDownList?
Setting the Style of the column to DropDown or DropDownList won't do much by itself. You have to provide the list of possible choices, also. You do that via the ValueList, or UltraDropDown control.
I'm not sure I am following you. What event are you using to set the Activation on the cell?
You are correct, that setting this property after the cell is already in edit mode will not work. But setting the Selected property on some other cell doesn't seem like the best way to get around that. What you should do is set the property in an event that fires before that cell gets activated, such as InitializeRow of the BeforeCelldeactivate or BeforeCellUpdate of some other cell.
In addition to using cell.Activation = Infragistrics.Win.UltraGrid.Activation.NoEdit, I used a this.Rows[cell.Row.ListIndex].Cells[0].Selected = true;
Why? Because when the Edit button is clicked, the event is fired, and the Activation property is set, however, since the cell is already in edit mode, the change to NoEdit doesnt take place till after you tab out of the cell. Therefore, it was necessary for me to select another cell so that its NoEdit property is reflected immediately.
Yep, that works. I found an example online and went with it. Thanks for the response Mike!
DCSteve said:Is there any way to make the text read only when you use the ColumnStyle.EditButton?
Take a look at the options for the Activation property on the cell. I forget which one is which, but there is an option which allows the cell to enter edit mode and get a cursor so the user can select text and even copy, but not modify the text. This setting is either NoEdit or ActivationOnly, I forget which one.
Hi Mike,
Mike Saltzman"]Okay, you lost me here. If the field in your data table is some custom object, then that's fine. You just override it's ToString method to return whatever you want the user to see on the screen.
Sorry for the confusion. What I meant was, for the dynamic cell that can be a drop down list; text field; or edit button, should I create different data sources for each one to bind to... Then I realized that for the DropDownList, I use the ValueList as its data source, and for the text field, and editor, I have the custom object that contains a .Value string property (no need to override the ToString method) which it binds to.
Mike Saltzman"]Setting the Style of the column to DropDown or DropDownList won't do much by itself. You have to provide the list of possible choices, also. You do that via the ValueList, or UltraDropDown control.
My question here was why you suggested a ComboBox instread of DropDownList.
Thanks for the replies!
-----------------------------------------------------------------------------------------------------------------------------------------
Mike, quick question.
I read a reply you made on a different post regarding read only cells. You said it could not be done.
Is there any way to make the text read only when you use the ColumnStyle.EditButton?
In my case, the user selects something in Column 2's drop down list. Column 3 then displays a default value, and the editor button to the right. I cant allow the user to edit that default value. The reason is because the edit button launches another UI that allows the user to modify the default value, as well as other properties that correspond to my custom object. The requirement is to only allow users to edit via the UI that is launched when the user clicks the edit button.