I use Difference class as my datasource in treelist. Then I would like to show different icon with node according to property value of the type Difference. Here is my Code:
treeList1_GetStateImage(object sender, DevExpress.XtraTreeList.GetStateImageEventArgs e)
{
TreeListColumn tlColumn = treeList1.Columns["DifferenceType"];
DifferenceTypeEnum differenceType = (DifferenceTypeEnum)e.Node.GetValue(tlColumn);
switch (differenceType)
{
case DifferenceTypeEnum.Added:
e.NodeImageIndex = 0;
break;
case DifferenceTypeEnum.Deleted:
e.NodeImageIndex = 1;
break;
case DifferenceTypeEnum.Modified:
e.NodeImageIndex = 2;
break;
default:
throw new Exception("Difference with not specified type");
}
I would like to have the same icons when selected and when not selected and thats all, nothiung else, but now each time I click on a node NodeImageIndex is changed to 0, WHen nodes arent selected everything work fine,
ehh Im tired of this ...
thanks for any help
I would suggest that you also handle the GetSelectImage event to define which image should be shown when a certain node is selected.
I just want to know how can I connect specified icon with node according to the property of the type. Lests say Im bound to the fruit list andd if fruit has gaot typoe property set to banana let the image be banana.png if apple then apple.png and so on :)
imageCollection connectied with this treelist has got these images with corresponding indexes.
Related
I have a form which contains several CheckedListBox items, along with other controls. I'm trying to loop through each the controls and set its property values. Unfortunately, the SetItemChecked property is is not available in the Control class, so I can't figure out how to manipulate the Checked state of the control.
Here's what I have so far:
for (int i = 0; i < Controls.Count(); i++) {
switch(Controls[i].GetType().ToString()) {
case "System.Windows.Forms.TextBox":
case "System.Windows.Forms.RichTextBox":
Controls[i].Text=i.ToString();
break;
case "System.Windows.Forms.CheckedListBox":
Controls[i].SetItemChecked(0,true);
// ^^ This line doesn't work, because SetItemChecked is not available
break;
default:
Controls[i].Tag=i;
break;
}
}
You can cast the Control into a CheckedListBox Like this:
(Controls[i] as CheckedListBox).SetItemChecked(0,true);
I'm not sure of this one, but it might work also:
CheckedListBox myCbList= (ChecekdListBox) Controls[i];
myCbList.SetItemChecked(0,true)
Once again I am in need of your assistance. I have two combobox's one called cmbRFR and one called cmbSubRFR. The items in the cmbRFR are:
Null
POSITIONING
ARTEFACT
PATIENT ID
EXPOSURE ERROR
TEST IMAGES
I need to set it up so that when the user selects one of the items in cmbRFR, it changes the items displayed in cmbSubRFR. cmbSubRFR should work as follows.
When user selects Null, the combobox should also display Null/a blank item.
When user selects POSITIONING:
Anatomy cut-off
Rotation
Obstructed view
Tube or grid centering
Motion
When user selects ARTEFACT the combobox should also display ARTEFACT.
When user select PATIENT ID:
Incorrect Patient
Incorrect Study/Side
User Defined Error
When user select EXPOSURE ERROR:
Under Exposure
Over Exposure
Exposure Malfunction
When user selects TEST IMAGES:
Quality Control
Service/Test
I have no code to provide for this one as I have no idea how to go about doing this. I have looked around at some other questions that are similar to this however I have found nothing that might help me.
Any suggestions would be helpful.
public partial class Form1 : Form
{
string cmbRFR_item;
public Form1()
{
InitializeComponent();
}
private void change_cmbSubRFR_items()
{
cmbSubRFR.Items.Clear();//Clear all items in cmbSubRFR comboBox.
switch (cmbRFR_item)//Adding your new items to cmbSubRFR.
{
case "Null":
cmbSubRFR.Items.Add("Null/a blank item");
cmbSubRFR.Text = "Null/a blank item";
break;
case "POSITIONING":
cmbSubRFR.Items.Add("Anatomy cut-off");
cmbSubRFR.Items.Add("Rotation");
cmbSubRFR.Items.Add("Obstructed view");
cmbSubRFR.Items.Add("Tube or grid centering");
cmbSubRFR.Items.Add("Motion");
cmbSubRFR.Text = "";
break;
case "ARTEFACT":
cmbSubRFR.Items.Add("ARTEFACT");
cmbSubRFR.Text = "ARTEFACT";
break;
case "PATIENT ID":
cmbSubRFR.Items.Add("Incorrect Patient");
cmbSubRFR.Items.Add("Incorrect Study/Side");
cmbSubRFR.Items.Add("User Defined Error");
cmbSubRFR.Text = "";
break;
case "EXPOSURE ERROR":
cmbSubRFR.Items.Add("Under Exposure");
cmbSubRFR.Items.Add("Over Exposure");
cmbSubRFR.Items.Add("Exposure Malfunction");
cmbSubRFR.Text = "";
break;
case "TEST IMAGES":
cmbSubRFR.Items.Add("Quality Control");
cmbSubRFR.Items.Add("Service/Test");
cmbSubRFR.Text = "";
break;
}
}
private void cmbRFR_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbRFR_item!= cmbRFR.SelectedItem.ToString())//This will control your changes in cmbRFR about selected item and call change_cmbSubRFR_items()
{
cmbRFR_item = cmbRFR.SelectedItem.ToString();
change_cmbSubRFR_items();
}
}
}
There are two ways to go about solving this. First the "correct way", which is to set the DataSource property. Create lists for each combobox, like this:
var _positioningItems = new List<string> { "Anatomy cut-off", "Rotation", "Obstructed view" };
var _patientIdItems = new List<string> { "Incorrect Patient", "Incorrect Study/Side", "User Defined Error" };
Then subscribe to the OnSelectedIndexChange event on the cmbRFR combobox and then in the event handler, set the DataSource to the appropriate list.
The other way to do it, which I'm not in favor of, is to create comboboxes for each cmbRFR item, then hide them all and only show the appropriate one to the user. Subscribe to the OnSelectedIndexChange event on the cmbRFR combobox and hide/show the appropriate combobox.
I have a form in C# with a drop down box. When that drop down box gets changed, I want it to load a custom user control into a panel. I get no compile errors, no runtime errors, but I also get no visible user control. The idea here is that each user control understands the configuration for a different scenario. I want to encapsulate each scenario in its own control and the drop down box allows the user to select the scenario, which loads the control for the user to perform configuration. By adjusting the options in the drop down, I can customize what scenarios a given customer has. As I said, my problem is I cannot get any of the controls to become visible. This is the code I am using for the drop down index change event handler:
private void ddlCollectorType_SelectedIndexChanged (object sender, EventArgs e)
{
m_currentControl = null;
pnlDeviceConfig.Controls.Clear ();
switch ((string) ddlCollectorType.SelectedItem)
{
case "SEL-421":
SEL421ASCIIControl s421 = new SEL421ASCIIControl (this);
m_currentControl = s421;
pnlDeviceConfig.Controls.Add (s421);
break;
case "SEL-421 (FTP)":
break;
case "GE D60":
GED6061850Control geD60 = new GED6061850Control (this);
m_currentControl = geD60;
pnlDeviceConfig.Controls.Add (geD60);
break;
case "GE D60 (TFTP)":
break;
case "MiCOM P442":
break;
}
}
I've only created a couple of the user controls so far, hence the empty case statements. When I make selections that should show me something, I get nothing (confirmed in the debugger that I am hitting the case statement body). Any help will be greatly appreciated!
To follow up on my comment, I'm guessing that the position and/or dimensions of your control are not set.
Try something like:
...
SEL421ASCIIControl s421 = new SEL421ASCIIControl (this);
m_currentControl = s421;
pnlDeviceConfig.Controls.Add (s421);
// TODO: Set real size and position.
s421.Left = 0;
s421.Top = 0;
s421.Width = 100;
s421.Height = 50;
break;
...
You also may use the Dock and Anchor properties of your control.
1 You can replace your Menu with PlaceHolder, he is ideal control for adding controls
here an example : http://www.developerfusion.com/code/3826/adding-controls-to-placeholders-dynamically/
2 And for your case you can try to adjust visible property of panel to true
What i'm trying to do is select an item in my listview, and it works! That is it works once, the first time a select an item it go's well, the second time a get an argument out of range exception on features[0].SubItems[1].Text; on the zero.
this is what i have:
private void listViewFeatures_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection features = listViewFeatures.SelectedItems;
string feature = features[0].SubItems[1].Text;
BL_AddReport addReport = new BL_AddReport(this.databaseConnectionString);
Dictionary<string, bool> pictures = addReport.GetpicturesFromFeature(feature);
foreach (KeyValuePair<string, bool> pic in pictures)
{
if (pic.Value) {
pictureBoxCar.Image = Image.FromFile(pic.Key);
}
else
{
pictureBoxEquip.Image = Image.FromFile(pic.Key);
}
}
}
Does anyone know what the problem is?
I'm betting you'd get this exception if you clicked off of the listview as well.
Remember that this event is for selection changes.. which may mean that something was selected and now nothing is. In fact, according to this an event is fired once for every thing that is selected. Take a look at that link for more information and designs around this problem if that is the case for you.
Otherwise just check to make sure that your "features" variable has anything inside of it before indexing into it
I would need to know how to let the programatically selected node make graphically in the state "selected" like the user clicked on it. SelectedNode only makes this one internally selected. Thank you very much!
The reason it does not show as highlighted is due to the tree view not having focus. This is in a button click event on my test form:
TreeView1.SelectedNode = TreeView1.Nodes(2);
TreeView1.Focus();
Which highlights the node properly. if you remove the Focus(); call it doesn't highlight until you click into the tree view (anywhere in the tree view, not necessarily on to the node that you want to be selected).
TreeView1.SelectedNode.BackColor = SystemColors.HighlightText; // This will work
Above solutions will only set the focus on it but will not change the highlight view of it.
This works for me for .net 3.5:
Set the treeview component's DrawMode property to: OwnerDrawAll
Then in the DrawNode event write the following:
if (((e.State & TreeNodeStates.Selected) != 0) && (!MyTreeView.Focused))
e.Node.ForeColor = Color.Blue;
else
e.DrawDefault = true;
And in the BeforeSelect event have:
if (MyTreeView.SelectedNode != null)
MyTreeView.SelectedNode.ForeColor = Color.Black;
e.Node.ForeColor = Color.Blue;
I don't know if it helps you or not but check the taborder of the the page and make sure that the tree view control has tab order of 0
Here is what I got to work:
void myProcedure()
{
// Hookup a DrawMode Event Handler
this.myTV.DrawNode += myTV_DrawNode;
// Set DrawMode and HideSelection
this.myTV.DrawMode = TreeViewDrawMode.OwnerDrawText;
this.myTV.HideSelection = false;
// Make sure the TreeView has Focus
this.myTV.Focus();
// Make sure the TreeView is Selected
this.myTV.Select();
// If the TreeView has a Node, I want to select the first Node to demonstrate.
if (this.myTV.Nodes.Count > 0)
{
// Make sure the node is visible
this.myTV.Nodes[0].EnsureVisible();
// Make sure the Node is Selected
this.myTV.SelectedNode = myTV.Nodes[0];
}
// Make sure the SelectedNode IS the Node that we programmatically want to select.
textBox1.Text = this.myTV.SelectedNode.Text;
// if we display sanityCheck1 string, it actually is the correct node.text
// Make sure .NET runtime knows the Node is selected
textBox1.Text += " is Selected = " + this.myTV.SelectedNode.IsSelected.ToString();
}
Following up: laalto answered the How to HighLight the TreeView.Node. The following code in the DrawNode Event Handler, from samball's answer, properly highlights the TreeView.Node based on its Selected State.
private void myTV_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
// first, let .NET draw the Node with its defaults
e.DrawDefault = true;
// Now update the highlighting or not
if (e.State == TreeNodeStates.Selected)
{
e.Node.BackColor = SystemColors.Highlight;
e.Node.ForeColor = SystemColors.HighlightText;
}
else
{
e.Node.BackColor = ((TreeView)sender).BackColor;
e.Node.ForeColor = ((TreeView)sender).ForeColor;
}
}
Platform = C# .NET 4.5 in Windows 10, Visual Studio 2015
TreeView1.SelectedNode = TreeView1.Nodes(2);
this.ActiveControl = TreeView1;
This works for me (.net 4.7)
The underlying Win32 control supports this (think it's TVIS_DROPHILITED), but I can't see the same functionality exposed through the TreeView control.
As theraneman says, you could fake it with the TreeNode.ForeColor and BackColor properties...
I had an similar issue and wanted to have a TreeView node selected (highlighted) on form load.
Maybe someone has the same problem, too.
I first tried Pondidum's solution. Without success.
But then I found the solution in another thread: Simply set the TabIndex of the TreeView to 0.
In that case you don't need to set the focus. Just choose the node that should be selected by using SelectedNode and set the TabIndex. That's it.
Not sure, but can you not change the background color of that node?