Hi,
i need help.
How to when select item from listview from Form1 and click button, to open it Form2 and focus that item to combobox.
Thank you in advance !
DO NOT DEAL WITH THIS MEMBER
You will need to pass a reference to the listview item collection to the form2 instance (for example through the constructor).
(Jan 6, 2018 05:08 AM)Ninja Wrote: You will need to pass a reference to the listview item collection to the form2 instance (for example through the constructor).
Which code for example ?
(Jan 6, 2018 10:37 AM)PeraPeric Wrote: Which code for example ?
Put the selected item in a variable, for example like this:
Code string item = listView.SelectedItems[0].Text;
Then you can pass it to the other form using a constructor, wich you could approach like this
Code private string itemForm1;
public Form2(string selected item)
{
itemForm1 = item;
InitializeComponent();
}
Then all you have to do is add the string itemForm1 to the combobox.
DO NOT DEAL WITH THIS MEMBER
(Jan 6, 2018 11:04 AM)Tommy Chong- Wrote: Put the selected item in a variable, for example like this:
Code string item = listView.SelectedItems[0].Text;
Then you can pass it to the other form using a constructor, wich you could approach like this
Code private string itemForm1;
public Form2(string selected item)
{
itemForm1 = item;
InitializeComponent();
}
Then all you have to do is add the string itemForm1 to the combobox.
It is best to send the item not as a string but as its original type, as all a combobox does is call the ToString method on it.
Something doesn't work.
This is database table:
CREATE TABLE [dbo].[Klijent] (
[klijentId] INT IDENTITY (1, 1) NOT NULL,
[naziv_klijenta] VARCHAR (50) NOT NULL,
[telefon] CHAR (15) NOT NULL,
PRIMARY KEY CLUSTERED ([klijentId] ASC)
);
Code Form1:
private void buttonPrikazi_Click(object sender, RoutedEventArgs e)
{
PostojeciKorisnik korisnik = new PostojeciKorisnik();
korisnik.itemForm1 = listViewPregled.SelectedItem.ToString();
korisnik.Show();
}
Code Form2:
public string itemForm1;
public PostojeciKorisnik(string item)
{
InitializeComponent();
this.itemForm1 = item;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
comboBoxKlijent.Items.Add(itemForm1);
}
If you want to focus on combobox there's .focus method so put in on the on_load of your form2.
DO NOT DEAL WITH THIS MEMBER
@OP, pass a reference to the collection to the second form, then bind it as the datasource to the combobox, then focus on the item you need.
Jan 9, 2018 12:02 PM
(This post was last modified: Jan 9, 2018 12:03 PM by 0xDEAD10CC.)
This really depends on what you have for your data sources and how you populate the listview and combobox. It's not the best idea to expose more than you need through any kind of references being passed around. If your collection is the same between the two UI components too, you could probably just get away with passing an int for the index to focus... If you need to modify that item, then you need a reference of some sort or some kind of callback. Many ways to do it but this is not enough information to provide a solution towards the best approach.
Where you say something doesn't work, what actually isn't working??
|