Objectlistview doubleclick explained - c#

I'm trying to implement the doubleclick function in an objectlistview object.
According the developer, one should use ItemActivate instead of MouseDoubleClick.
So I came up with this:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
ListView.SelectedIndexCollection col = treeListView.SelectedIndices;
MessageBox.Show(col[0].ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}
Which comes up with a value for each double clicked row.
But how do I get the details from that row?
Here's the whole solution I'm now using:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
var se = (StructureElement)treeListView.GetItem(treeListView.SelectedIndex).RowObject;
MessageBox.Show(se.id.ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}

Which comes up with a value for each double clicked row. But how do I get the details from that row?
I think you have to access the RowObject using the underlying OLVListItem like this:
private void treeListView_ItemActivate(object sender, EventArgs e) {
var item = treeListView.GetItem(treeListView.SelectedIndex).RowObject;
}

This is how I'm now getting the data out of the treelistview:
private void treeListView_ItemActivate(object sender, EventArgs e)
{
try
{
var se = (StructureElement)treeListView.GetItem(treeListView.SelectedIndex).RowObject;
MessageBox.Show(se.id.ToString());
}
catch (Exception e3)
{
globals.logfile.error(e3.ToString());
globals.logfile.flush();
}
finally
{
}
}

Related

AxMsRdpClient8NotSafeForScripting.Connect() not working No Exceptions, Not Errors

I'm trying to check my RDP credentials using c#
Here is my reference : Remote Desktop using C#.NET
And here is what I've done so far :
private void testBtn_Click(object sender, EventArgs e) {
try {
AxMsRdpClient8NotSafeForScripting ax = new AxMsRdpClient8NotSafeForScripting();
ax.OnLoginComplete += Ax_OnLoginComplete;
ax.OnLogonError += Ax_OnLogonError;
ax.OnFatalError += Ax_OnFatalError;
ax.Size = new Size(1, 1);
ax.CreateControl();
ax.Server = ipTbx.Text;
ax.UserName = userNameTbx.Text;
MsRdpClient8NotSafeForScripting sec = (MsRdpClient8NotSafeForScripting)ax.GetOcx();
sec.AdvancedSettings8.ClearTextPassword = passwordTbx.Text;
sec.AdvancedSettings8.EnableCredSspSupport = true;
ax.Connect();
} catch (Exception ex) {
MessageBox.Show("Error : " + ex.Message);
}
}
private void Ax_OnFatalError(object sender, IMsTscAxEvents_OnFatalErrorEvent e) {
SaySomething();
}
private void Ax_OnLogonError(object sender, IMsTscAxEvents_OnLogonErrorEvent e) {
SaySomething();
}
private void Ax_OnLoginComplete(object sender, EventArgs e) {
SaySomething();
}
public void SaySomething() {
MessageBox.Show("Worked!");
}
As you can see, I've done everything in the article way. But nothing happens, even an exception would be worthy.
Any Idea?

C# Windows From add/remove list [duplicate]

This question already has answers here:
Move selected items from one listbox to another in C# winform
(7 answers)
Closed 7 years ago.
I need to add a "slushbucket" (ServiceNow term) to a C# Windows Form, like the image below, but can't figure out what they're actually called so therefore can't look into how they're created.
Does anyone know what they're called, or better yet how to implement one into a windows form?
I need it to list values from Table1 on the left, then when they are added to the right hand list and the save button is clicked, the values are written to Table2. It would also need to show existing values for Table2 if there are any.
Assuming that this is how the form looks like:
Form1.Png
Here is a simple code that implements your idea as follows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 6; i <= 10; i++)
{
listBox1.Items.Add("item" + i);
}
for (int i = 1; i <= 5; i++)
{
listBox2.Items.Add("item" + i);
}
}
private void btnSave_Click(object sender, EventArgs e)
{`
if (listBox2.Items.Count >0)
{
string message = "";
foreach (var item in listBox2.Items)
{
message += item + "\n";
}
MessageBox.Show(message);
}`
/// write here the code that save listbox1 and listbox2 items
/// to a text file or a database table and load this text file or
/// the database table inside these two listboxes you could write the
/// code that load data to the two list boxes in the constructor instead
/// of the tow for loops thats i've provided.
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (!listBox2.Items.Contains(listBox1.SelectedItem))
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
}
else
{
MessageBox.Show("Item already exists");
}
}
catch (ArgumentNullException exc)
{
MessageBox.Show("Nothing selected to add");
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
try
{
if (!listBox1.Items.Contains(listBox2.SelectedItem))
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
}
else
{
MessageBox.Show("Item already exists");
}
}
catch (ArgumentNullException exc)
{
MessageBox.Show("Nothing selected to remove");
}
}
}
hope that's what you were looking for :)
Thanks.
This is the image output :
and your code is below. I hope this will be helpful for you.
public partial class Form1 : Form
{
ArrayList Table1;
ArrayList Table2;
bool isSaved = false;
public Form1()
{
InitializeComponent();
Table1 = new ArrayList();
Table2 = new ArrayList();
Table1.Add("Value1");
Table1.Add("Value2");
Table1.Add("Value3");
Table1.Add("Value4");
Table1.Add("Value5");
}
private void populateListBox1() {
for (int i = 0; i < Table1.Count;i++)
{
listBox1.Items.Add(Table1[i]);
}
}
private void Form1_Load(object sender, EventArgs e)
{
populateListBox1();
}
private void refreshListBox1() {
listBox1.Items.Clear();
populateListBox1();
}
private void addToRight() {
try
{
listBox2.Items.Add(Table1[listBox1.SelectedIndex]);
Table1.RemoveAt(listBox1.SelectedIndex);
}
catch
{
MessageBox.Show("You have to select an item first !");
}
refreshListBox1();
}
private void removeFromRight(){
if (isSaved)
{
try
{
listBox1.Items.Add(Table2[listBox2.SelectedIndex]);
Table1.Add(Table2[listBox2.SelectedIndex]);
isSaved = false;
}
catch
{
MessageBox.Show("You have to select an item first !");
isSaved = true;
}
try
{
Table2.RemoveAt(listBox2.SelectedIndex);
listBox2.Items.RemoveAt(listBox2.SelectedIndex);
isSaved = false;
}
catch
{
if(listBox2.Items.Count==0)
MessageBox.Show("This list is an empty list");
isSaved = true;
}
}
else {
MessageBox.Show("You have to click save button first !");
}
}
private void saveToTable2() {
for (int i = 0; i < listBox2.Items.Count;i++)
{
Table2.Add(listBox2.Items[i].ToString());
}
MessageBox.Show("Saved !");
isSaved=true;
}
private void btn_add_Click(object sender, EventArgs e)
{
addToRight();
}
private void btn_save_Click(object sender, EventArgs e)
{
saveToTable2();
}
private void btn_remove_Click(object sender, EventArgs e)
{
removeFromRight();
}
}
}

Sending cancel parameter C#

Okay, this is my whole code. Now... Detail_BeforePrint() will be called first, and xrPictureBox8_BeforePrint second.
Now I want to call Detail_BeforePrint e.Cancel = true; inside the else in xrPictureBox8_BeforePrint event.
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//here should e.Cancel = true be if it came from xrPictureBox_BeforePrint()
}
private void xrPictureBox8_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
try
{
if (xrPictureBox8.ImageUrl.Length > 0) { }
else
{
Detail_BeforePrint(null,[call Cancel parameter]);
}
}
catch (Exception)
{
}
}
Maybe something like this would help?
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
DoDetail_BeforePrint(e, false);
}
private void DoDetail_BeforePrint(System.Drawing.Printing.PrintEventArgs e, bool cancel)
{
if (cancel) e.Cancel = true;
//other things
}
private void xrPictureBox8_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
try
{
if (xrPictureBox8.ImageUrl.Length > 0) { }
else
{
DoDetail_BeforePrint(e, true);
//or just call e.Cancel = true here?
}
}
catch (Exception)
{
}
}

How to convert listbox DataContext to string in windows phone 7

I am using this sample code to get calendar appointments.
I want to convert items to string : for example show the first item in a message box.
What is the solution??
private void SearchAppointments_Click(object sender, RoutedEventArgs e)
{
Appointments appts = new Appointments();
appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
appts.SearchAsync(DateTime.Now, DateTime.Now.AddDays(1), 2,null);
}
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
try
{
//Bind the results to the list box that displays them in the UI.
AppointmentResultsData.DataContext = e.Results;
}
catch (System.Exception)
{
//That's okay, no results.
}
}
The results are IEnumerable and you can do it for example like this:
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
try
{
AppointmentResultsData.DataContext = e.Results;
MessageBox.Show(e.Results.ElementAt<Appointment>(0).Subject.ToString());
}
catch (System.Exception) { }
}
Of course instead of a Subject you can show other properties of Appointment Class.

Calling variable from another event

I want to call a variable from another event, for example
public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
var ccc = lblTicketsA;
}
public void btnSubmit_Click(object sender, EventArgs e)
{
try
{
ccc.text = "test";
}
catch (Exception ex)
{
lblDisplay.Text = ex.Message;
}
}
thank you
Make ccc an instance field like this:
private SomeType ccc;
public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.ccc = lblTicketsA;
}
public void btnSubmit_Click(object sender, EventArgs e)
{
try
{
this.ccc.text = "test"
}
catch (Exception ex)
{
lblDisplay.Text = ex.Message;
}
}

Categories