How to catch click on eto ImageViewCell? - forms

I have a column in my grid that displays a garbage icon. When clicked I want to catch that click and delete the row.
How do I listen for a click on an ImageViewCell?

gridControl.CellClick += Stats_CellClick;
private void Stats_CellClick(object sender, GridViewCellEventArgs e)
{
if (e.Column == 3)
{
RulesDocAdapter rda = (RulesDocAdapter)e.Item;
rda.Delete();
UpdateRulesDoc(Globals.RulesDoc);
}
}

Related

Changing Title font in chart using textbox #C

After writing a Title in textbox and clicking a button, title changes,
How to change the title font as well?
private void button4_Click(object sender, EventArgs e)
{
string chartTitle;
try
{
chartTitle = textBox1.Text.ToString();
chart1.Titles.Clear();
chart1.Titles.Add(chartTitle);
//chartTitle.Font = new Font("Tahoma",11,FontStyle.Bold); (Not working)
}
catch
{
MessageBox.Show("Error!");
}
}

clicking a button inside tab control/ tab page - revit form

i am trying too use a tabControl panel to put multiple features in a single form.
how can i make a button inside a tab clickable? it seems as if the button is not active when its being clicked from inside its parent tab.
how can i make the button active from inside the tab container?
notes:
i tryied to place a call for the button inside the tabPage, but then - when i clicked the button nothing happened, but when i clicked somewhere random inside the tab itself the button activity started.
buttons decleration + tabcontrol decleration:
// a button to add the associated views to the right listbox (listbox2):
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
selectedItemText = listBox1.SelectedItem.ToString();
selectedItemIndex = listBox1.SelectedIndex;
foreach(Level lev in levels)
{
if(lev.Name == selectedItemText)
{
pickedLevel = lev;
}
}
foreach(Element view in views)
{
View v = view as View;
if (v.GenLevel != null)//check if the view is indeed a level
{
if (v.ViewType == ViewType.CeilingPlan && v.GenLevel.Name == pickedLevel.Name)//check if the plan is cielling, and if it has the same level as chosen
{
listBox2.Items.Add(v.Name);
}
}
}
dataBindings();
}
// set the listbox1 back:
private void dataBindings()
{
listBox1.DataSource = null;
listBox1.DataSource = levelNames;// string list
}
// button to clear the right listbox
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
dataBindings();
}
// the tab decleration--> what goes here?
private void tabPage1_Click(object sender, EventArgs e)
{
}

InteropServices.ComException when closing a document after adding a new document from the ribbon

I'm trying to write a Word add-in that uses a CustomTaskPane. I'm able to create the CustomTaskPane and synchronize it between open documents, and I get no errors as long as I use the Word menu when I add a new or open an existing document. However, if I add a new document through a ribbon button that calls Globals.ThisAddIn.Application.Documents.Add(), I start getting COMExceptions when I close documents.
The issue appears to be when I add a new document using the button click event in CtpMainRibbon.cs instead of through the Word menu, the Globals.ThisAddIn.Application.ActiveWindow property is invalid after closing an open document. On the get for the CurrentCustomTaskPane property, ActiveWindow returns a System.Runtime.InteropServices.COMException: 'This command is not available because no document is open.' at Microsoft.Office.Interop.Word.ApplicationClass.get_ActiveWindow(). I've searched for the error but most of the issues are when people try to use the Word Interop on a server or an ASP.net page, but I'm getting this on my development machine. Also, if I use the Document.Add() method, the Show button's check status doesn't display correctly (if I have a CustomTaskPane open in one document, then click the New Document button on the ribbon, the new document's Show button is checked even though the task pane isn't visible. If I switch to a different window then switch back to the new document, the button's checked status updates to unchecked.
I've tried looping through Globals.ThisAddIn.CustomTaskPanes to see if there's a mismatch between the ctp.Window.Hwnd properties, but as far as I can tell, each ctp.Window has its own unique Hwnd. I get the message even when there are other documents and windows open.
Here's the 2 pertinent code files. I use CurrentCustomTaskPane so the ribbon button can sync up with the Visible property of the task pane.
ThisAddIn.cs:
private const string TaskPaneTitle = "Main Custom Task Panel";
public static CustomTaskPane CurrentCustomTaskPane
{
get
{
return Globals.ThisAddIn.CustomTaskPanes
.FirstOrDefault(ctp => !ctp.Control.IsDisposed &&
Globals.ThisAddIn.Application.ActiveWindow != null &&
ReferenceEquals(ctp.Window, Globals.ThisAddIn.Application.ActiveWindow) &&
ctp.Title == TaskPaneTitle);
}
}
private void InternalStartup()
{
Startup += ThisAddIn_Startup;
Shutdown += ThisAddIn_Shutdown;
}
private void ThisAddIn_Startup(object sender, EventArgs e)
{
if (Application.Documents.Count > 0)
AddNewTaskPane(Application.ActiveDocument);
Word.ApplicationEvents4_Event event4 = Application;
event4.NewDocument += OnNewDocument;
event4.DocumentOpen += OnDocumentOpen;
event4.WindowActivate += ApplicationOnWindowActivate;
}
private static void ThisAddIn_Shutdown(object sender, EventArgs e) { }
private void OnNewDocument(Word.Document doc) => AddNewTaskPane(doc);
private void OnDocumentOpen(Word.Document doc) => AddNewTaskPane(doc);
private void ApplicationOnWindowActivate(Word.Document doc, Word.Window wn) => SetRibbonButtonToggle();
private void AddNewTaskPane(Word._Document doc)
{
RemoveOrphanedTaskPanes();
CustomTaskPane newPane = CustomTaskPanes.Add(new MainCustomTaskPanel(), TaskPaneTitle, doc.ActiveWindow);
newPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft;
newPane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
newPane.Width = 700;
newPane.VisibleChanged += TaskPaneOnVisibleChanged;
}
private void TaskPaneOnVisibleChanged(object sender, EventArgs e) => SetRibbonButtonToggle();
private void SetRibbonButtonToggle()
{
if (CurrentCustomTaskPane != null)
Globals.Ribbons.CtpWordRibbon.RbnButtonShowTaskPane.Checked = CurrentCustomTaskPane.Visible;
}
private void RemoveOrphanedTaskPanes()
{
foreach (CustomTaskPane ctp in CustomTaskPanes)
{
if (ctp.Window == null || ctp.Control.IsDisposed)
CustomTaskPanes.Remove(ctp);
}
}
CtpWordRibbon.cs:
private void RbnButtonShowCtp_Click(object sender, RibbonControlEventArgs e)
{
if (ThisAddIn.CurrentCustomTaskPane != null)
ThisAddIn.CurrentCustomTaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}
private void RbnButtonCreateNewDocument_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.Application.Documents.Add();
}
There's obviously a difference between how Word handles adding a new document through the Word menu and adding it with the Application.Documents.Add() method. How can I check to see if the ActiveDocument property is going to throw an COMException before I actually access it? Or is there an better way to create a new document through the ribbon, or handle the OnNewDocument event so I'm not getting these errors?

Old Screen From Activity Gets Displayed When Back Button Used

I guess I do not understand how things like the "Back Button" affect how Activities behave.
Here is my main activity screen shot:
If the user clicks the bookmark icon in the upper right, my BookmarksActivity displays like so:
Here the user clicks the Add button to add the bookmark and I call finish() in my BookmarksActivity class and the screen returns to the my MainActivity ...
Now let's say the user wants to delete a bookmark, they would again click the bookmark icon which presents the user with this screen:
Now the user can click on the delete button resulting in this screen:
Now the user wants to get back to the MainActivity's screen by pressing the Back Button, doing so removes the keyboard as one would expect, resulting in this screen:
But now the user still wants to get back the main screen, so they click the Back Button again, but instead of the main screen one would expect to see they see this one!
Now there is no bookmark in my SQLite database yet one is being displayed. If the user clicks that back button again they do, finally, get the main activity screen ...
... and if they click on the Bookamrk icon you can see that there is no bookmark:
Thanks for bearing with me and that lengthy description of the problem. Here is what I believe to be the pertinent snippets of code:
Here's where the delete happens:
public class BookMarksBaseAdapter extends BaseAdapter {
...
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.bookmark, null);
TextView tv_bookmark_name = (TextView)vi.findViewById(R.id.bookmark_name);
TextView tv_bookmark_clock = (TextView)vi.findViewById(R.id.bookmark_clock);
Button deleteButton = (Button)vi.findViewById(R.id.btn_delete_bookmark);
final bookMark bookmark = new bookMark(data.get(position).get_bookmark_name(), data.get(position).get_bookmark_track(), data.get(position).get_bookmark_clock(), 0);
final String bookmark_name = bookmark.get_bookmark_name();
final int ibookmark_clock = bookmark.get_bookmark_clock();
// Setting all values in listview
tv_bookmark_name.setText(bookmark_name);
tv_bookmark_clock.setText(utils.milliSecondsToTimer(ibookmark_clock));
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d( TAG, "delete button clicked line 73" );
db.deleteBookmark(bookmark);
v.getContext().startActivity(new Intent(v.getContext(), com.redcricket.myApp.BookMarksActivity.class));
}
});
return vi;
}
And here is the an snippet from my BookmarkActivity onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
currentChapterTitle = com.redcricket.myApp.MainActivity.getTrackTitle(0);
currentTrack = com.redcricket.myApp.MainActivity.getCurrentSongIndex();
currentTrackPosition = "00:00:00";
db = new Databasehandler(this);
db.getWritableDatabase();
utils = new Utils();
try {
currentChapterTitle = com.redcricket.myApp.MainActivity.getCurrentTrackTitle();
} catch (Exception e) {
Log.d( TAG, "expection line 27" );
e.printStackTrace();
}
try {
icurrentTrackPosition = com.redcricket.myApp.MainActivity.getCurrentTrackPosition();
currentTrackPosition = utils.milliSecondsToTimer(icurrentTrackPosition);
} catch (Exception e) {
Log.d( TAG, "expection line 34" );
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.bookmarks);
try {
new_bookmark_name = (EditText) findViewById(R.id.new_bookmark_name);
} catch (Exception e) {
Log.d( TAG, "expection line 43" );
e.printStackTrace();
}
try {
new_bookmark_name.setText( currentChapterTitle );
} catch (Exception e) {
Log.d( TAG, "expection line 49" );
e.printStackTrace();
}
try {
new_bookmark_clock = (TextView) findViewById(R.id.new_bookmark_clock);
} catch (Exception e) {
Log.d( TAG, "expection line 55" );
e.printStackTrace();
}
try {
new_bookmark_clock.setText( currentTrackPosition );
} catch (Exception e) {
Log.d( TAG, "expection line 61" );
e.printStackTrace();
}
try {
addButton = (Button) findViewById(R.id.btn_add_new_bookmark);
} catch (Exception e) {
Log.d( TAG, "expection line 43" );
e.printStackTrace();
}
addButton.setOnClickListener(this);
bookMarkList = db.getAllBookmarks();
// add list
bookmark_list=(ListView)findViewById(R.id.bookmarks_list);
adapter=new BookMarksBaseAdapter(this, bookMarkList, this);
bookmark_list.setAdapter(adapter);
I must be doing something wrong somewhere. I have tried to override the onBackButton method and have it call finish but that didn't help at all. My best guess is that this line in wrong:
v.getContext().startActivity(new Intent(v.getContext(), com.redcricket.myApp.BookMarksActivity.class));
I call that when the delete button get pressed.
Any help welcomed. Thanks!
I am assuming Main is one activity, book mark is another activity and book mark delete is another activity. Unless you tell an activity to have no history or explicitly finish it before going to another activity it will stay in the activity stack.
In your example the user goes MainActivity -> BookMarkActivty then back to MainActivity through on back pressed which removed BookMarkActivity from the stack. Its all good.
In your other example the user goes MainActivity -> BookMarkActivity -> DeleteActivity
the question here is when they click delete are you finishing DeleteActivty or starting a new BookMarkActivty?
It looks like you are starting a new BookMarkActivty, finished the old BookMarkActivity and ended up with a stack of Main - DeleteBookMark - BookMark after the deletion process.
Don't finish bookmark when they choose to do a delete and set the delete activity to have no history or explicitly finish it after delete.
Doh! I figured out what I needed to do. I need to save the Activity that gets passed to the constructor of my BookMarksBaseAdapter class as a private member like so ...
public class BookMarksBaseAdapter extends BaseAdapter {
private Activity activity;
...
BookMarksBaseAdapter (Activity a, ArrayList<bookMark> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
utils = new Utils();
db = new Databasehandler(a);
}
... then I call call activity.finish() when the delete button gets pressed like this ...
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
db.deleteBookmark(bookmark);
activity.finish();
}
});

GWT button click event

i have one window panel in my project.
and i add one button to it.
when i click the button,i want two event to fire.
one event is to hide that window,which i achieve through
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
hide();
super.onClick(button, e);
}
});
Window.add(button);
and second i want to pop up another window at the same time on the same button click..what to do?
help me out
I think this should solve your problem :
final boolean evenClick = false;
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
if (!evenClick) {
hide();
super.onClick(button, e);
}
else {
//DO YOUR SECOND CLICK STUFF
}
evenClick = !evenClick;
}
});
Window.add(button);