I'm new on C# and i have many difulties, but now i'm still trying add an eventhandler to declared control like a variable, but if i use the delegate instruction i cant put this events because when i use the declaration:
private delegate void listView1_MouseUp(object sender, MouseEventArgs e)
Many error appears in a procedure that i caught in this forum, but i will put all procedure to you see.
private void Form1_Load(object sender, EventArgs e)
{
// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = false;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending;
//Hide Column Header
listView1.HeaderStyle = ColumnHeaderStyle.None;
// Create three items and three sets of subitems for each item.
ListViewItem[] ItemsView = new ListViewItem[Quant_Items];
while (Item_Number <= (Quant_Items - 1))
{
ItemsView[Item_Number] = new ListViewItem(Item_name + Item_Number);
while (Sub_Item <= (Quant_SubItems - 1))
{
ItemsView[Item_Number].SubItems.Add("SubItem" + Sub_Item);
Sub_Item++;
}
Item_Number++;
}
Sub_Item = 0;
while (Sub_Item <= (Quant_SubItems - 1))
{
listView1.Columns.Add("Coluna" + Sub_Item);
Sub_Item++;
}
//Add the items to the ListView.
listView1.Items.AddRange(ItemsView);
//Autosize ListView
listView1.Bounds = new Rectangle(new Point(10, 10), new Size(Quant_SubItems * 70, Quant_Items * 18));
// Add the ListView to the control collection.
this.Controls.Add(listView1);
listView1.MouseUp += new EventHandler(listView1_MouseUp);
}
//____________________________________________________________________
private delegate void listView1_MouseUp(object sender, MouseEventArgs e)
{
ListViewHitTestInfo i = listView1.HitTest(e.X, e.Y);
SelectedLSI = i.SubItem;
if (SelectedLSI == null)
return;
int border = 0;
switch (listView1.BorderStyle)
{
case BorderStyle.FixedSingle:
border = 1;
break;
case BorderStyle.Fixed3D:
border = 2;
break;
}
int CellWidth = SelectedLSI.Bounds.Width;
int CellHeight = SelectedLSI.Bounds.Height;
int CellLeft = border + listView1.Left + i.SubItem.Bounds.Left;
int CellTop = listView1.Top + i.SubItem.Bounds.Top;
// First Column
if (i.SubItem == i.Item.SubItems[0])
CellWidth = listView1.Columns[0].Width;
TxtEdit.Location = new Point(CellLeft, CellTop);
TxtEdit.Size = new Size(CellWidth, CellHeight);
TxtEdit.Visible = true;
TxtEdit.BringToFront();
TxtEdit.Text = i.SubItem.Text;
TxtEdit.Select();
TxtEdit.SelectAll();
}
private void listView2_MouseDown(object sender, MouseEventArgs e)
{
HideTextEditor();
}
private void listView2_Scroll(object sender, EventArgs e)
{
HideTextEditor();
}
private void TxtEdit_Leave(object sender, EventArgs e)
{
HideTextEditor();
}
private void TxtEdit_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
HideTextEditor();
}
private void HideTextEditor()
{
TxtEdit.Visible = false;
if (SelectedLSI != null)
SelectedLSI.Text = TxtEdit.Text;
SelectedLSI = null;
TxtEdit.Text = "";
}
}
}
Thanks for your help!
Just use this:
private void listView1_MouseUp(object sender, MouseEventArgs e)
{
...
}
The delegate keyword doesn't belong in the method declaration, it's not valid in that context.
When you handle an event, you must supply a handler that matches the delegate type expected by this event. Loosley speaking, you need a method with the same signature expected by the handler.
For MouseUp, you need to supply a MouseEventHandler, see https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventhandler(v=vs.110).aspx
You need to change the event subscription to
listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);
Then change the signature of your handler to
private void listView1_MouseUp(object sender, MouseEventArgs e) { /*..*/}
Related
I am developing an exe file
Which creates dynamic textboxes(no. of textboxes depends upon the user input in the one already provided textbox),
In the beginning it focus on the 1st textbox,
It should move focus to next textbox on click of "ENTER" key.
What I'm trying is:
private void Form1_Load(object sender, EventArgs e)
{
int a = 10;
for (int i = 1; i < 5; i++)
{
TextBox txtbx;
txtbx = new TextBox();
txtbx.Location = new Point(10, a);
a += 30;
this.Controls.Add(txtbx);
if(i==1)
{
txtbx.Focus();
}
}
}
public void Form1_KeyPessed(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.ENTER)
{
SendKeys.Send("{TAB}");
}
}
Need to use Control.TabIndex Property and you need to bind key down event for each newly created Text box
Try this :
private void Form1_Load(object sender, EventArgs e)
{
int a = 10;
for (int i = 1; i < 5; i++)
{
TextBox txtbx;
txtbx = new TextBox();
txtbx.Location = new Point(10, a);
txtbx.KeyDown += Txtbx_KeyDown; //Added
txtbx.TabIndex = i; //Added
a += 30;
this.Controls.Add(txtbx);
if (i == 1)
{
txtbx.Focus();
}
}
}
Now add Key down handler
//Added
private void Txtbx_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Enter))
{
SendKeys.Send("{TAB}");
}
}
I have an application where I can add a textBox on the screen and move it.
When I add more than two textBox, I double-click on top of two textbox and a line connects both.
My question is: How to make the line move along with the textBox?
code below:
public partial class principal : Form
{
int posMouseFormX, posMouseFormY;
int posMouseTXT_X, posMouseTXT_Y;
int posActTXT_X, posActTXT_Y;
bool txtPressionado = false;
int qntClick;
Pen myPen = new Pen(System.Drawing.Color.DarkGreen, 1);
Graphics Tela;
List<TextBox> listaNós = new List<TextBox>();
List<Point> origem = new List<Point>();
List<Point> destino = new List<Point>();
Point ponto1, ponto2;
ContextMenuStrip menu;
public principal()
{
InitializeComponent();
menu = new ContextMenuStrip();
menu.Items.Add("Remover");
menu.ItemClicked += new ToolStripItemClickedEventHandler(contextMenuStrip1_ItemClicked);
}
//TextBox event when the mouse moves over the TXT
private void txtMover_MouseMove(object sender, MouseEventArgs e)
{
TextBox textBox = sender as TextBox;
posMouseFormX = textBox.Location.X + e.Location.X;
posMouseFormY = textBox.Location.Y + e.Location.Y;
if (txtPressionado == true) moverTxt(textBox);
}
//Retrieve the X and Y coordinates where clicked within the component.
private void txtMover_MouseDown(object sender, MouseEventArgs e)
{
posMouseTXT_X = e.Location.X;
posMouseTXT_Y = e.Location.Y;
txtPressionado = true;
}
private void txtMover_MouseUp(object sender, MouseEventArgs e)
{
txtPressionado = false;
}
private void moverTxt(TextBox a)
{
a.Location = new System.Drawing.Point(posMouseFormX - posMouseTXT_X, posMouseFormY - posMouseTXT_Y);
posActTXT_X = a.Location.X;
posActTXT_Y = a.Location.Y;
System.Drawing.Graphics graphicsObj;
graphicsObj = this.CreateGraphics();
}
//insert new TextBox
private void sb_Inserir_No_Click(object sender, EventArgs e)
{
TextBox noFilho = new TextBox();
noFilho = new System.Windows.Forms.TextBox();
noFilho.Location = new System.Drawing.Point(379, 284);
noFilho.Size = new System.Drawing.Size(100, 30);
noFilho.TabIndex = 20;
noFilho.Text = "";
noFilho.BackColor = Color.White;
posActTXT_X = noFilho.Location.X;
posActTXT_Y = noFilho.Location.Y;
this.Controls.Add(noFilho);
noFilho.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
noFilho.DoubleClick += new System.EventHandler(this.textBox1_Click);
noFilho.MouseUp += new System.Windows.Forms.MouseEventHandler(txtMover_MouseUp);
noFilho.MouseDown += new System.Windows.Forms.MouseEventHandler(txtMover_MouseDown);
noFilho.MouseMove += new System.Windows.Forms.MouseEventHandler(txtMover_MouseMove);
noFilho.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
noFilho.ContextMenuStrip = menu;
}
//event to resize the txt on the screen as the content.
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox textBox1 = sender as TextBox;
Size size = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);
textBox1.Width = size.Width + 10;
textBox1.Height = size.Height;
}
//Event to control the connection between two give us when double click on the textbox
private void textBox1_Click(object sender, EventArgs e)
{
TextBox textBox1 = sender as TextBox;
int meio = textBox1.Size.Width / 2;
Tela = CreateGraphics();
qntClick = qntClick + 1;
if (this.qntClick == 1)
{
origem.Add(ponto1);
ponto1 = new Point(textBox1.Location.X + meio, textBox1.Location.Y);
}
if (this.qntClick == 2)
{
qntClick = 0;
destino.Add(ponto2);
ponto2 = new Point(textBox1.Location.X + meio, textBox1.Location.Y);
DesenhaSeta(Tela, ponto1, ponto2);
}
}
//draw arrow between two TXT
void DesenhaSeta(Graphics Tela, Point x, Point y)
{
myPen.StartCap = LineCap.Triangle;
myPen.EndCap = LineCap.ArrowAnchor;
Tela.DrawLine(myPen, x, y);
}
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ContextMenuStrip menu = sender as ContextMenuStrip;
//recuperando o controle associado com o contextmenu
Control sourceControl = menu.SourceControl;
DialogResult result = MessageBox.Show("Tem Certeza que deseja remover o nó selecionado?", "Excluir", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(result == DialogResult.Yes)
{
sourceControl.Dispose();
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
// Determine whether the key entered is the F1 key. Display help if it is.
if (e.KeyCode == Keys.Space)
{
TextBox textBox1 = sender as TextBox;
novoNó tela = new novoNó(textBox1.Text);
tela.Show();
}
}
}
Each control, TextBox included has a Move, event. Put an Invalidate() call there!
The lines should be drawn in the Paint event of the container that holds the TextBoxes, probably the Form; if it is the Form indeed call this.Invalidate().
Please move the line drawing code out of the DoubleClick event into the Paint event or else the lines will not persist, say minimize/maximize events or other situation, when the system has to redraw the application!
You probably will need to create a data structure to maintain information about which TextBox-pairs need to be connected, maybe a List<Tuple> or a List<someStructure>. This would get filled/modified in the DoubleClick event, then call this.Invalidate() and in the Form.Paint you have a foreach loop over the list of TextBox-pairs..
If you are drawing on the Form do make sure to turn DoubleBuffered on!
Update: To compare the reults here is a minimal example the expects two TextBoxes on a Form:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.DoubleBuffered = true;
pairs.Add(new Tuple<Control, Control>(textBox1, textBox2));
}
List<Tuple<Control, Control>> pairs = new List<Tuple<Control, Control>>();
Point mDown = Point.Empty;
private void Form2_Paint(object sender, PaintEventArgs e)
{
foreach (Tuple<Control, Control> cc in pairs)
drawConnection(e.Graphics, cc.Item1, cc.Item2);
}
void drawConnection(Graphics G, Control c1, Control c2)
{
using (Pen pen = new Pen(Color.DeepSkyBlue, 3f) )
{
Point p1 = new Point(c1.Left + c1.Width / 2, c1.Top + c1.Height / 4);
Point p2 = new Point(c2.Left + c2.Width / 2, c2.Top + c2.Height / 4);
G.DrawLine(pen, p1, p2);
}
}
void DragBox_MouseDown(object sender, MouseEventArgs e)
{
mDown = e.Location;
}
void DragBox_MouseMove(object sender, MouseEventArgs e)
{
TextBox tb = sender as TextBox;
if (e.Button == MouseButtons.Left)
{
tb.Location = new Point(e.X + tb.Left - mDown.X, e.Y + tb.Top - mDown.Y);
}
}
void DragBox_MouseUp(object sender, MouseEventArgs e)
{
mDown = Point.Empty;
}
private void DragBox_Move(object sender, EventArgs e)
{
this.Invalidate();
}
}
I have a WinForm with DataGridView, my goal is to drag one column and drop it on other column index. I know column reordering is possible by using AllowUserToOrderColumns = true. But I have to perform other operations on DGV. That's why I need the target column index at a mouse-up event. To do that, I use HitTestInfo:
System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
myHitTest = dataGrid1.HitTest(e.X, e.Y);
int p = myHitTest.ColumnIndex;
When I click on the first DGV column, this code runs and gives me the column's index (p). The problem is when I drop it on the other column of DGV, I'd like to know the target column's index, with the same code p = -1, I think because the HitTestInfo member returns a value on a MouseDown and not on a MouseUp. If anyone can tell me how to do it, it would be very great.
You can create two HitTestInfo objects, one in the MouseDown and one in the MouseUp.
IMO, you also should use the DataGridView.HitTestInfo class, not DataGrid.HitTestInfo and try to not call or name DataGridViews DataGrids, which is a similar but different Control from WPF!
DataGridView.HitTestInfo myHitTestDown, myHitTestUp;
int visibleColumnDown, visibleColumnUp;
private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
{
myHitTestUp = dataGrid1.HitTest(e.X, e.Y);
visibleColumnUp = getVisibleColumn(dataGrid1, e.X);
}
private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
{
myHitTestDown = dataGrid1.HitTest(e.X, e.Y);
visibleColumnDown = getVisibleColumn(dataGrid1, e.X);
}
Update: To find the visible index of a column after the columns have been reordered simply use:
dataGrid1.Columns[myHitTestUp.ColumnIndex].DisplayIndex;
Before I found that, I wrote this little helper function, which does the same:
int getVisibleColumn(DataGridView dgv, int x)
{
int cx = dgv.RowHeadersWidth;
int c = 0;
foreach (DataGridViewColumn col in dgv.Columns)
{
cx += col.Width; if ( cx >= x) return c; c++;
}
return -1;
}
To find out which Column was shuffled seems to be a bit harder. There is an event, which gets called for each column that was affected and it always gets called first for the one that was dragged along. Here is one way to do it:
Create to variables at class level:
List<DataGridViewColumn> shuffled = new List<DataGridViewColumn>();
DataGridViewColumn shuffledColumn = null;
Remember the first column:
private void dgvLoadTable_ColumnDisplayIndexChanged(
object sender, DataGridViewColumnEventArgs e)
{
if (shuffledColumn == null) shuffledColumn = e.Column;
}
Forget what happend before:
private void dgvLoadTable_MouseDown(object sender, MouseEventArgs e)
{
shuffledColumn = null;
}
Now you can use it. Selecting Columns is, however, not going well with shuffling them! If you do
shuffledColumn.Selected = true;
it will only be selected if the SelectionMode is either FullColumnSelector ColumnHeaderSelect- In either mode the shuffling will not work, I'm afraid..
You could use drag'n'drop for that.
Assume you have a Form with a DataGridView named dataGridView1.
Initially don't forget to allow drag'n'drop for DataGridView:
dataGridView1.AllowDrop = true;
The event handler which replaces the desired functionality of MouseUp would be the dataGridView1_DragDrop, and the target column's index is colIndexOfItemUnderMouseToDrop:
private Rectangle dragBoxFromMouseDown;
private int colIndexFromMouseDown;
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Proceed with the drag and drop, passing in the list item.
dataGridView1.DoDragDrop(colIndexFromMouseDown, DragDropEffects.Move);
}
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// Get the index of the item the mouse is below.
colIndexFromMouseDown = dataGridView1.HitTest(e.X, e.Y).ColumnIndex;
if (colIndexFromMouseDown != -1)
{
// Remember the point where the mouse down occurred.
// The DragSize indicates the size that the mouse can move
// before a drag event should be started.
Size dragSize = SystemInformation.DragSize;
// Create a rectangle using the DragSize, with the mouse position being
// at the center of the rectangle.
dragBoxFromMouseDown = new Rectangle(
new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)),
dragSize);
}
else
// Reset the rectangle if the mouse is not over an item in the ListBox.
dragBoxFromMouseDown = Rectangle.Empty;
}
private void dataGridView1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
// If the drag operation was a move then remove and insert the column.
if (e.Effect == DragDropEffects.Move)
{
// The mouse locations are relative to the screen, so they must be
// converted to client coordinates.
Point clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
// Get the column index of the item the mouse is below.
int colIndexOfItemUnderMouseToDrop = dataGridView1.HitTest(clientPoint.X, clientPoint.Y).ColumnIndex;
if (colIndexOfItemUnderMouseToDrop == -1)
return;
colIndexOfItemUnderMouseToDrop = dataGridView1.Columns[colIndexOfItemUnderMouseToDrop].DisplayIndex;
// Now we have the column's display index.
if (e.Data.GetDataPresent(typeof(int)))
{
int colToMove = (int)e.Data.GetData(typeof(int));
dataGridView1.Columns[colToMove].DisplayIndex = colIndexOfItemUnderMouseToDrop;
// Select the column:
dataGridView1.Columns[colToMove].Selected = true;
}
}
}
EDIT
New approach:
private DataGridViewColumn columnToMove;
public Form1()
{
InitializeComponent();
dataGridView1.Columns.AddRange(new DataGridViewColumn[]
{
new DataGridViewTextBoxColumn { Name = "AAA", SortMode = DataGridViewColumnSortMode.NotSortable },
new DataGridViewTextBoxColumn { Name = "BBB", SortMode = DataGridViewColumnSortMode.NotSortable },
new DataGridViewTextBoxColumn { Name = "CCC", SortMode = DataGridViewColumnSortMode.NotSortable }
});
dataGridView1.Rows.Add(2);
dataGridView1.AllowUserToOrderColumns = true;
dataGridView1.MouseDown += dataGridView1_MouseDown;
dataGridView1.ColumnDisplayIndexChanged += dataGridView1_ColumnDisplayIndexChanged;
}
private void dataGridView1_ColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
{
if (e.Column == columnToMove)
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
e.Column.Selected = true;
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
var hti = dataGridView1.HitTest(e.X, e.Y);
if (hti.Type == DataGridViewHitTestType.ColumnHeader)
{
columnToMove = dataGridView1.Columns[hti.ColumnIndex];
dataGridView1.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
}
}
I've got panel on which by default are two comboboxes and one "+" button which creates two new combo boxes bellow the first one, I can create multiple (n) rows with two combo boxes and everything is working, I just can't figure out how to get values of those boxes?
Here's code for creating (adding) controls
private void btnCreateFilter_Click(object sender, EventArgs e)
{
y += comboBoxHeight;
ComboBox cb = new ComboBox();
cb.Location = new Point(x, y);
cb.Size = new Size(121, 21);
panelFiltri.Controls.Add(cb);
yDrugi += comboBoxHeight;
ComboBox cbSql = new ComboBox();
cbSql.Location = new Point(xDrugi, yDrugi);
cbSql.Size = new Size(121, 21);
panelFiltri.Controls.Add(cbSql);
btnCancel.Location = new Point(btnCancel.Location.X, btnCancel.Location.Y + 25);
btnSaveFilter.Location = new Point(btnSaveFilter.Location.X, btnSaveFilter.Location.Y + 25);
}
And here's code where I'm lost:
private void btnSaveFilter_Click(object sender, EventArgs e)
{
int i;
foreach (Control s in panelFiltri.Controls)
{
//GOT LOST
}
}
You can get the text in the ComboBox as
private void btnSaveFilter_Click(object sender, EventArgs e)
{
foreach (Control control in panelFiltri.Controls)
{
if (control is ComboBox)
{
string valueInComboBox = control.Text;
// Do something with this value
}
}
}
I don't really know what you're trying to achieve... Maybe this will help you along...
private void btnSaveFilter_Click(object sender, EventArgs e)
{
foreach (ComboBox comboBox in panelFiltri.Controls)
{
var itemCollection = comboBox.Items;
int itemCount = itemCollection.Count; // which is 0 in your case
}
}
I am new at C# and it seems the following code below does not seem to select my combobox value:
private void button1_Click(object sender, EventArgs e)
{
cbPortNumber.SelectedValue = 3;
or
cbPortNumber.setValue("3");
or
cbPortNumber.SelectedIndex = cbPortNumber.FindString("3");
or
cbPortNumber.SelectedIndex = cbPortNumber.Items.IndexOf(cbPortNumber.Items.FindByValue("HDMI 4"));
}
The dropdown looks like this:
All code above does not seem to select HDMI 4 on the list... I dont have any errors but i also don't have it being selected.
Any help would be great!
update showing combobox
UPDATE 2
//
// cbPortNumber
//
this.cbPortNumber.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
this.cbPortNumber.Enabled = false;
this.cbPortNumber.FormattingEnabled = true;
this.cbPortNumber.Location = new System.Drawing.Point(174, 40);
this.cbPortNumber.Name = "cbPortNumber";
this.cbPortNumber.Size = new System.Drawing.Size(133, 21);
this.cbPortNumber.TabIndex = 11;
this.cbPortNumber.Text = "global_hdmi_port";
this.helpPortNumber.SetToolTip(this.cbPortNumber, "The HDMI port number, to which you connected your USB-CEC adapter.");
this.cbPortNumber.SelectedIndexChanged += new System.EventHandler(this.cbPortNumber_SelectedIndexChanged);
#region Global settings
public CECSettingByte HDMIPort
{
get
{
if (!_settings.ContainsKey(KeyHDMIPort))
{
CECSettingByte setting = new CECSettingByte(KeyHDMIPort, "HDMI port", 1, _changedHandler) { LowerLimit = 1, UpperLimit = 15, EnableSetting = EnableHDMIPortSetting };
setting.Format += delegate(object sender, ListControlConvertEventArgs args)
{
ushort tmp;
if (ushort.TryParse((string)args.Value, out tmp))
args.Value = "HDMI " + args.Value;
};
Load(setting);
_settings[KeyHDMIPort] = setting;
}
return _settings[KeyHDMIPort].AsSettingByte;
}
}
Update 3
And this is what fires the action after selecting something in that dropdown:
private void OnSettingChanged(CECSetting setting, object oldValue, object newValue)
{
if (setting.KeyName == CECSettings.KeyHDMIPort)
{
CECSettingByte byteSetting = setting as CECSettingByte;
if (byteSetting != null)
{
if (!Settings.OverridePhysicalAddress.Value)
Config.HDMIPort = byteSetting.Value;
CECActions.SetConnectedDevice(Settings.ConnectedDevice.Value, byteSetting.Value);
}
}
So this code is working fine for me:
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 2;
}
you can not access a ItemSource if there are no items to access. The simple way is to Init the items over the Desinger
( Sory for the nonlocalized IDE ) than you can set the Property SelectedIndex to a Index that exits. The other way is to Add all HDMI items with the Combobox1.Items.Add function.
If you ever used Forms in VB ... its still the same
public Form1()
{
InitializeComponent();
var hdmi = "HDMI";
for (int i = 1; i < 15; i++)
{
comboBox1.Items.Add( hdmi + i);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Items.Count >= 2)
comboBox1.SelectedIndex = 2;
}