Home › Forums › WinForms controls › Xceed Grid for WinForms › How to display "yes" or "no" instead of boolean in vb
-
AuthorPosts
-
#13227 |
Hello,
Well I am having some problems for making a column display “Yes” or “No” instead of 1 or 0.
Thanks in advance.
Alonso CayroImported from legacy forums. Posted by alcayro (had 6477 views)
I think a GridComboBox would do the trick. Just use a GridComboBox as the CellViewer for the column. It should have 3 elements: true/”yes”, false/”no” and DBNull.Value/”?”.
Imported from legacy forums. Posted by Tommy (had 289 views)
“Well I am having some problems for making a column display “Yes” or “No” instead of 1 or 0.”
Like Tommy wrote, you could use a Xceed.Grid.Editors.GridComboBox as cell viewer:
Like this (C#):
ArrayList refTypeAL = new ArrayList(); //Used to display in a combo
refTypeAL.Add(new DictionaryEntry(“1”, “Yes”));
refTypeAL.Add(new DictionaryEntry(“0”, “No”));Xceed.Grid.Editors.GridComboBox status_comboEditor = new Xceed.Grid.Editors.GridComboBox();
Xceed.Grid.Editors.GridComboBox status_comboViewer = new Xceed.Grid.Editors.GridComboBox();status_comboEditor.DataSource = refTypeAL;
status_comboEditor.ValueMember = “Key”;
status_comboEditor.DisplayMember = “Value”;
status_comboEditor.DropDownWidth = 400;
status_comboEditor.TabStop = false;status_comboViewer.DataSource = refTypeAL;
status_comboViewer.ValueMember = “Key”;
status_comboViewer.DisplayMember = “Value”;
status_comboViewer.DropDownWidth = 400;
status_comboViewer.TabStop = false;gridControl1.Controls.Add(status_comboViewer);
status_comboViewer.Location = new System.Drawing.Point(-1000,-1000);gridControl1.Columns[ “Test1” ].CellEditor = status_comboEditor;
gridControl1.Columns[ “Test1” ].CellViewer = new ControlViewer( status_comboViewer, “SelectedValue” );Regards
ThomasImported from legacy forums. Posted by C# (had 398 views)
You don’t need 2 different GridComboBoxes, you can use 1 as both CellViewer and CellEditor. You also don’t have to add it to the Controls-collection of the gridcontrol, and you don’t need to wrap the viewer inside a ControlViewer-object.
A modified version:ArrayList refTypeAL = new ArrayList();
refTypeAL.Add(new DictionaryEntry(“1”, “Yes”));
refTypeAL.Add(new DictionaryEntry(“0”, “No”));Xceed.Grid.Editors.GridComboBox combo = new Xceed.Grid.Editors.GridComboBox();
combo.DataSource = refTypeAL;
combo.ValueMember = “Key”;
combo.DisplayMember = “Value”;grid.Columns[“myColumn”].CellEditor = combo;
grid.Columns[“myColumn”].CellViewer = combo;Imported from legacy forums. Posted by Tommy (had 343 views)
A little correction: I think the 2 DictionaryEntry-objects should have <b>true</b> and <b>false</b> as their keys. If you want to display a string for cells that are not yet filled in (not yet true and not yet false), you can also add an entry for that.
ArrayList refTypeAL = new ArrayList(3);
refTypeAL.Add(new DictionaryEntry(<b>true</b>, “Yes”));
refTypeAL.Add(new DictionaryEntry(<b>false</b>, “No”));
refTypeAL.Add(new DictionaryEntry(<b>DBNull.Value</b>, “(empty)”));… // the rest of the code
Imported from legacy forums. Posted by Tommy (had 202 views)
If the cell’s datatype is string, the true/false as DictionaryEntry key’s will not work.
Imported from legacy forums. Posted by C# (had 519 views)
Ex.
Yes = “0”
No = “1”
Cancel = “2”Imported from legacy forums. Posted by C# (had 696 views)
You’re right. It all depends on the datatype. But I assumed it was a boolean, because the title of the thread says ‘… instead of boolean in vb’.
The <i>empty</i>-value however always has to be <b>DBNull.Value</b>, since that is used by the system.
Imported from legacy forums. Posted by Tommy (had 200 views)
ok. sorry
I did not see the title.
/Thomas
Imported from legacy forums. Posted by C# (had 487 views)
Thanks, you have been very helpful.
Imported from legacy forums. Posted by alcayro (had 7147 views)
-
AuthorPosts
- You must be logged in to reply to this topic.