When using telerik winforms dropdownlist, the dropdownstyle have only 2 options, ie, dropdown and dropdownlist. But in visualstudio combobox has one more style option, ie, dropdownstlye="simple".
How can we achieve the "simple" style option in telerik winforms dropdownlist.
Please advice.
Thanks
Jim
There is no such functionality available out of the box, however, using RadTextBox and RadListControl you can easily achieve it. Just align them properly one beneath the other on the form and use the following events:
RadListControl.SelectedIndexChanged - use to set the text of the text box, when item in the control is selected
RadTextBox.KeyDown - when enter is pressed, find an item with the entered text and if such exists, select it
RadTextBox.TextChanged - clear the selected item in the list control
Here is also a snippet.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AddTextBox();
AddListControl();
radListControl1.SelectedIndexChanged += radListControl1_SelectedIndexChanged;
radTextBox1.KeyDown += radTextBox1_KeyDown;
radTextBox1.TextChanged += radTextBox1_TextChanged;
}
void radTextBox1_TextChanged(object sender, EventArgs e)
{
radListControl1.SelectedItem = null;
}
void radTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
radListControl1.SelectedItem = radListControl1.FindItemExact(radTextBox1.Text, false);
}
}
void radListControl1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (e.Position > -1)
{
radTextBox1.Text = radListControl1.Items[e.Position].Text;
}
}
Related
According to MSDN, MultiSelect option allows user to select multiple rows with Ctrl or Shift modifier, but I can select multiple rows with left mouse button only without pressing any control modifier. Is it possible to stop multiple selection without pressing Shift or Ctrl modifiers?
I'm using Windows 10 and Visual Studio 2019.
Maybe you can disable the selection via Mouse Event.
Here is the workaround you can refer to.
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
dataGridView1.ClearSelection();
dataGridView1.CurrentCell.Selected = true;
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
dataGridView1.MouseMove += dataGridView1_MouseMove;
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
dataGridView1.MouseMove -= dataGridView1_MouseMove;
}
}
The test result,
How can i get data from devexress gridcontrol's detail row via double-click.
If i focused on child row gridview's double click event doesn't catch.
i tried this method, but my request is catching data by double click
private void gcOperasyonlar_FocusedViewChanged(object sender, DevExpress.XtraGrid.ViewFocusEventArgs e)
{
if (e.View != null && e.View.IsDetailView)
(e.View.ParentView as GridView).FocusedRowHandle = e.View.SourceRowHandle;
GridView detailView = gcOperasyonlar.FocusedView as GridView;
MessageBox.Show(detailView.GetFocusedRowCellValue("Kalip").ToString());
}
thanks for your help
There is also an easier way:
ColumnView cv = _gridControlxyz.FocusedView as ColumnView;
selectedRow row = cv.GetRow(cv.FocusedRowHandle)
I found this code on the forum, It might be useful as long as your grid is not editable (so that mouse click doesn't activate the editable field).
private void gridView1_DoubleClick(object sender, EventArgs e) {
GridView view = (GridView)sender;
Point pt = view.GridControl.PointToClient(Control.MousePosition);
DoRowDoubleClick(view, pt);
}
private static void DoRowDoubleClick(GridView view, Point pt) {
GridHitInfo info = view.CalcHitInfo(pt);
if(info.InRow || info.InRowCell) {
string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();
MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
}
}
http://www.devexpress.com/Support/Center/Question/Details/A2934
Let's say you have two gridviews (I'm guessing you're using gridviews in your grid control): gvMaster and gvDetail.
You should implement event DoubleClick for your gvDetail in order to achieve desired functionality:
private void gvDetail_DoubleClick(object sender, EventArgs e) {
var gv = sender as GridView; // sender is not gvDetail! It's an instance of it. You have as many as there are rows in gvMaster
var row = gv.GetDataRow(e.FocusedRowHandle); // or use gv.GetRow(e.FocusedRowHandle) if your datasource isn't DataSet/DataTable (anything with DataRows in it)
MessageBox.Show(row["Kalip"].ToString());
}
I have a datagrid with DatagridComboboxcolumn as one of the column in winforms.
Combobox is contain two items Y,N.
If user select Y,I need to change the value for the two columns of same row.
Same thing will happen when User select "N".
I have tried to register ComboBox_SelectedIndexChanged as follows.
But not able to get the row index or coulmn index for the selected row and change the values of the same row columns.
Please help me asap.
private void gridTesr_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
if(combo != null)
{
// Remove an existing event-handler, if present, to avoid
// adding multiple handlers when the editing control is reused.
combo.SelectedIndexChanged -=new EventHandler(ComboBox_SelectedIndexChanged);
// Add the event handler.
combo.SelectedIndexChanged +=new EventHandler(ComboBox_SelectedIndexChanged);
}
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
Try declaring your own method to handle the ComboBox.SelectedIndexChanged event.
private void gridTesr_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
if(combo != null)
{
// Remove an existing event-handler, if present
combo.SelectedIndexChanged -= this.MyComboEventHandler;
// Add the event handler
combo.SelectedIndexChanged += this.MyComboEventHandler;
}
}
private void MyComboEventHandler(object sender, EventArgs e)
{
string myValue = ((ComboBox)sender).SelectedItem.ToString();
DataGridViewCell cell = gridTesr.CurrentCell;
MessageBox.Show(string.Format("The current ComboBox resides in the Row {0} and Column {1} and it currently has the {3} value.",
cell.RowIndex, cell.ColumnIndex, myValue));
}
I would like to ask you something about VS2010 combobox (CB) component...
Is it possible to make something like multilevel (categorised) CB? I mean, can I divide items in CB into categories or somthing like this?
There is similar component in html (tag optgroup) - it's exactly what I need:
multilevel combobox in html
Thanx very much for answer
P.S.: Sorry for my english, I hope I've described it clearly
If you change the DrawMode of the ComboBox to OwnerDrawFixed and you can use the DrawItem event to draw your header and your items. But there is nothing you can do to prevent the user from selecting a header item.
private List<string> groupItems = new List<string>();
private void Form1_Load(object sender, EventArgs e)
{
groupItems.Add("Great Bands");
groupItems.Add("Great Bandages");
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.Items.Add("Great Bands");
comboBox1.Items.Add("Led Zeppelin");
comboBox1.Items.Add("Steppenwolf");
comboBox1.Items.Add("Great Bandages");
comboBox1.Items.Add("Band-Aid");
comboBox1.Items.Add("Curad");
}
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index > -1)
{
string drawText = comboBox1.Items[e.Index].ToString();
if (groupItems.Contains(drawText))
{
using (Font font = new Font(comboBox1.Font, FontStyle.Bold))
e.Graphics.DrawString(drawText, font, Brushes.Black, e.Bounds);
}
else
e.Graphics.DrawString(drawText, comboBox1.Font, Brushes.Black, new Rectangle(16, e.Bounds.Top, e.Bounds.Width - 16, e.Bounds.Height));
e.DrawFocusRectangle();
}
}
I have a WPF Datagrid and I'm implementing drag and drop functionality.
The datagrid has a list of "files" and the user can drag them and copy the file to the desktop.
This is done like this:
string[] files = new String[myDataGrid.SelectedItems.Count];
int ix = 0;
foreach (object nextSel in myDataGrid.SelectedItems)
{
files[ix] = ((Song)nextSel).FileLocation;
++ix;
}
string dataFormat = DataFormats.FileDrop;
DataObject dataObject = new DataObject(dataFormat, files);
DragDrop.DoDragDrop(this.myDataGrid, dataObject, DragDropEffects.Copy);
I have two questions:
1. When I want to drag multiple items- this is a problem because after I select a couple and start clicking on one to start dragging- only that gets selected and the other items get deselected. I tried the solution that is given here but for some reason it doesn't work.
2. I want to remove the dragged item from the datagrid after it is copied. The problem is that I don't know how to check if the file was copied or whether the user just dragged it on the screen without copying it.
I hope you can help me solve these problems.
Thanks!
I think this i what you are looking for:
add this code to the DataGrid__PreviewMouseLeftButtonDown event handler:
private void DataGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.startingPosition = e.GetPosition(null);
DependencyObject dep = (DependencyObject)e.OriginalSource;
// iteratively traverse the visual tree until get a row or null
while ((dep != null) && !(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}
//if this is a row (item)
if (dep is DataGridRow)
{
//if the pointed item is already selected do not reselect it, so the previous multi-selection will remain
if (songListDB.SelectedItems.Contains((dep as DataGridRow).Item))
{
// now the drag will drag all selected files
e.Handled = true;
}
}
}
and now the draging won't change you selection.
Have a good luck!
I used that article to write my answer
Improved on finding the row.
Also selecting the clicked row when not dragging is added.
This now behaves exactly as other Microsoft selectors (eg Outlook)
public TreeDataGrid()
{
Loaded += TreeDataGrid_Loaded;
LoadingRow += new EventHandler<DataGridRowEventArgs>(TreeDataGrid_LoadingRow);
}
#region MultiSelect Drag
object toSelectItemOnMouseLeftButtonUp;
void TreeDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(Row_PreviewMouseLeftButtonDown);
e.Row.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(Row_PreviewMouseLeftButtonUp);
}
void Row_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DataGridRow row = (DataGridRow)sender;
toSelectItemOnMouseLeftButtonUp = null; // always clear selecteditem
if (SelectedItems.Contains(row.Item)) //if the pointed item is already selected do not reselect it, so the previous multi-selection will remain
{
e.Handled = true; // this prevents the multiselection from disappearing, BUT datagridcell still gets the event and sets DataGrid's private member _selectionAnchor
toSelectItemOnMouseLeftButtonUp = row.Item; // store our item to select on MouseLeftButtonUp
}
}
void Row_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
DataGridRow row = (DataGridRow)sender;
if (row.Item == toSelectItemOnMouseLeftButtonUp) // check if it's set and concerning the same row
{
if (SelectedItem == toSelectItemOnMouseLeftButtonUp) SelectedItem = null; // if the item is already selected whe need to trigger a change
SelectedItem = toSelectItemOnMouseLeftButtonUp; // this will clear the multi selection, and only select the item we pressed down on
typeof(DataGrid).GetField("_selectionAnchor", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, new DataGridCellInfo(row.Item, ColumnFromDisplayIndex(0))); // we need to set this anchor for when we select by pressing shift key
toSelectItemOnMouseLeftButtonUp = null; // handled
}
}
#endregion