How can I find which column header is selected? - c#-4.0

I have a datagrid view in my form and I like to sort the table by clicking the columnheader.
I choose the Columnheader DoubleClick Event for writing the code but I don't know, how I should tell which column header is selected.
Is there any way for it or I have to change my mind?

Look at the DataGridView's ColumnHeaderMouseClick event.
When the event fires you can get the index value of the clicked column through the event's DataGridViewCellMouseEventArgs.ColumnIndex property. The article I linked has an example.

In both ColumnHeaderMouseClick and OnColumnHeaderMouseDoubleClick events you can do:
private void DataGridView1_OnColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
int column = e.ColumnIndex;
}

Related

Prevent row click event in YUI Datatable

I have a YUI data table. When we click on any row of this data table, there is an alert box.
vtgtTbl.on('rowClickEvent',function(oArgs){
alert("a");
}
I have a checkbox. what i want is that when that checkbox is true then row click will work, and not when it is false. so is there is any method in YUI to attach and detach these events
Within the rowClick event handler callback you can add a check for the checkbox in the following way
vtgtTbl.on('rowClickEvent',function(oArgs){
var checkBoxNode = Y.one('#checkboxId');
if (checkBoxNode.checked) {
alert("a");
}
}
Hope it solves the problem.

Preserve Selection when Scrolling GXT

I am using Sencha GXT Grid for a web app. But what I see is after scrolling the grid the selection is gone. I tried to preserve the selection by catching the scroll event and restoring the selected items (using setsecteditems() ). But was not successful also.
Is there a method to preserve the selection in sencha GXT grid.
Thanx
I have finally able to preserve the selection in Live grid view. I found two ways that I thought worth to share.It's kind of a hack :)
1. If you are receiving data from a server. You can maintain a boolean in server side data preserving the selection. and when you render rows in the client side you can add a style name to that row checking the boolean which is set previously.
the style name can be set using
grid.getView().setViewConfig(new GridViewConfig() {
#Override
public String getColStyle(Object model, ValueProvider<? super Data, ?> valueProvider, int rowIndex, int colIndex) {
return null;
}
#Override
public String getRowStyle(Objectmodel, int rowIndex) {
//Do the logic here and return the Style name
return null;
}
});
You can also maintain a list of keys in client side which contains the selected items. and use the previous method to add a style name if the row you are drawing is in the list.
Thanx :)

JavaFX2.2 TableView:How to make a table cell be edited without mouse click?

I've encounter a problem with editable table cells. I'm using the TableView in my project just as the Tutorial on Oracle.
According to it, I use the setCellFactory method to reimplement the table cell as a text field with the help of the TextFieldTableCell class. However, I found the steps is a little complex to get to the point where the cell can be edited:
Let the table cell be selected by using direction key.
Press “Enter” to converts the cell to a text filed so that it is ready to be edited.
Clicking in the text field allows the contents to be edited
The problem is step 3, that you must use the mouse to click before you can input data in this table cell.
So, is there a solution to avoid step 3? That is the text field allows the data inputting when you just press “Enter”(step 2).
By the way, English is not my native language. Hope I have made myself clear.
The Node can be focused manually. The TextFieldTableCell is a TableCell that has a Node (Graphic) TextField which will be rendered when the cell is in editing mode. You need to focus to this textField manually but by using TextFieldTableCell you cannot access to the textField. However if you would prefer the alternative way described in the tutorial you are referring, then you have a chance to focus. The only changed method from that tutorial is:
#Override
public void startEdit() {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);
textField.selectAll();
// Set the focus
Platform.runLater(new Runnable() {
#Override
public void run() {
textField.requestFocus();
}
});
}
To start editing in a TableView without mouse-click event, invoke TreeView.edit(rowIndex, tableColumn);
For example:
//create tableview object
TableView<YourModel> tableView = new TableView<>();
//create column
TableColumn<YourModel, String> column = new TableColumn<>("Property Name");
//add column to tableview
tableView.getColumns().add(column);
//... your cell factory and the rest
//add an item
tableView.getItems().add(new YourModel());
//if you want to edit the selected item, get its index
int selectedIndex = tableView.getSelectionModel().getSelectedIndex();
//fire edit
tableView.edit(selectedIndex, column);

C# TableLayoutPanel replace control?

I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.
// Replaces a drop down menu with a label of the same value
private void lockDropMenu(ComboBox dropControl)
{
TableLayoutPanelCellPosition pos = myTable.GetCellPosition(dropControl);
Label lblValue = new Label();
myTable.Controls.Remove(dropControl);
if (dropControl.SelectedItem != null)
{
lblValue.Text = dropControl.SelectedItem.ToString();
lblValue.Font = lblValue.Font = dropControl.Font;
// Just my preferred formatting
lblValue.AutoSize = true;
lblValue.Dock = System.Windows.Forms.DockStyle.Fill;
lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
myTable.Controls.Add(lblValue, pos.Column, pos.Row);
}
}

How to detect a CListCtrl selection change?

I want to execute some code when the user selects a row in a CListCtrl (report view, I don't care about the other viewing modes).
How do I catch this event? is there some message I can map or a method like "OnSelectionChanged" or something like that?
Also try:
BEGIN_MESSAGE_MAP(cDlgRun, CDialog)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST2, OnItemchangedList2)
END_MESSAGE_MAP()
/* ... */
void cDlgRun::OnItemchangedList2(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if ((pNMListView->uChanged & LVIF_STATE)
&& (pNMListView->uNewState & LVIS_SELECTED))
{
// do stuff...
}
}
There are a few notifications based on what's happening.
If you are selecting an item and nothing is selected yet, you will get one LVIF_STATE change notification: uNewState & LVIS_SELECTED. The newly selected item will be found at:
pNMListView->iItem
If an item is selected before you select a new object, you'll get three state changes:
First you will be informed that the previous item in focus is losing focus:
pNMListView->uOldState & LVIS_FOCUSED
Then you will be notified that the old item is being unselected:
pNMListView->uOldState & LVIS_SELECTED
Finally, you will get the new item selection state:
pNMListView->uNewState & LVIS_SELECTED
(again look at iItem for newly selected item)
So the pitfall we ran across is that, because item deselection results in two notifications, we were doing a lot of repetitive, sometimes detrimental, processing. What we ended up doing was only doing this processing for the 2nd message (pNMListView->uOldState & LVIS_SELECTED), and skipping the same processing after the loss of focus notification.
djeidot is right on.
I just want to add that there is no OnSelectionChanged() because the ListView supports multi-selection (although this can be disabled). Therefore, a single-selection listview will send you two events: Old item unselected AND New item selected.
On my Visual Studio 2010, the visual editor declares a callback in the dialog header file like this:
afx_msg void OnLbnSelchangeListOnvif();
and in the source file:
BEGIN_MESSAGE_MAP(CDialogOnvif, CDialog)
ON_LBN_SELCHANGE(IDC_LIST_ONVIF, &CDialogOnvif::OnLbnSelchangeListOnvif)
END_MESSAGE_MAP()
void CDialogOnvif::OnLbnSelchangeListOnvif()
{
// do stuff...
}

Resources