I'm trying to add a dataset into it for binding but i couldn't do it cause i get some errors that lead me to undo everything that i had done
i read telerik site and i studied their program too but it didn't help at all
in their site this was the code for binding
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
NwindDataSet nwindDataSet = new NwindDataSet();
CustomersTableAdapter customersTableAdapter = new CustomersTableAdapter();
customersTableAdapter.Fill(nwindDataSet.Customers);
this.radMultiColumnComboBox1.DataSource = nwindDataSet.Customers;
foreach (GridViewDataColumn column in this.radMultiColumnComboBox1.MultiColumnComboBoxElement.Columns)
{
column.BestFit();
}
}
void SetUpGrid()
{
RadGridView gridViewControl = this.radMultiColumnComboBox1.EditorControl;
gridViewControl.MasterTemplate.AutoGenerateColumns = false;
gridViewControl.Columns.Add(new GridViewTextBoxColumn("CustomerID"));
gridViewControl.Columns.Add(new GridViewTextBoxColumn("ContactName"));
gridViewControl.Columns.Add(new GridViewTextBoxColumn("ContactTitle"));
gridViewControl.Columns.Add(new GridViewTextBoxColumn("Country"));
gridViewControl.Columns.Add(new GridViewTextBoxColumn("Phone"));
}
is this code enough?
can someone pls help me with it
That's the programatically way to do it. If you have a bindingsource you can bind it with a pair of clicks, if not you can do it manual passing the values to the DatSource property
BUT, if you wanna add it to a gridview you can do it using the editor of RadGridView, and bind it in the same way as described above
Seems that you don't have clear how do it programatically, so I recomend you the easy way: do it with the RadMultiColumnBox Task (1st image) or RadGridViewEditor (2nd image), depend if you need it in a grid
I would also suggest looking in the column documentation: link
Related
I have a WebHierarchicalDatagrid where I manually create the columns in my PageLoad() event. None of my columns shows on initial page load, even though the datasource has data that matches the columns. (I DO set and bind after the columns are created/added to the grid). If I refresh (PostBack), then they show. I have cleared and reset the grid many ways.
If I define columns in markup then the initial page load works of course, but I need to dynamically create columns based on my user roles and if I clear and recreate the desired columns in my page load, page prerender, etc I get a viewstate error.
Seems that you cannot use markup and codebehind to define a grid. Would not be a problem, but I have a custom (user control) pager template defined in markup and I spent days trying to get create that in codebehind given I cannot just point the codebehind pager creation to use an existing user control. Total catch-22.
Infragistics grids are just too tweaky to deal with anymore. If you stay on the straight and narrow, they are good, but stray off the path and you are in big trouble!
AutoGenerateBands and AutoGenerateColumns should be set to false. Also, I don't know whether you are using GridView to configure the grid or not, although I wanted to let you know that WebHierarchicalDataGrid.Columns collections is relevant to the root band of the columns defined at designed time or from the markup. As for the columns that are auto generated, they could be accessed from WebHierarchicalDataGrid.GridView.Columns.
As I understand you are creating the columns from Page_Load event, try to do that on WHDG_Init. I am just curious what would be the result.
protected void WebHierarchicalDataGrid1_Init(object sender, EventArgs e)
{
WebHierarchicalDataGrid1.DataSource = new TestData().GetData();
WebHierarchicalDataGrid1.DataKeyFields = "ID";
WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("ID", "ID"));
WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("Name", "Name"));
WebHierarchicalDataGrid1.Bands.Add(CreateNewBand("ChildBand_0", "Child", "ChildID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ChildID", "ChildID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ID", "ID"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("Address", "Address"));
WebHierarchicalDataGrid1.Bands["ChildBand_0"].Behaviors.CreateBehavior<Filtering>();
}
public static BoundDataField CreateNewBoundDataField(string columnName, string headerText)
{
BoundDataField boundDataField = new BoundDataField();
boundDataField.DataFieldName = columnName;
boundDataField.Key = columnName;
boundDataField.Header.Text = headerText;
return boundDataField;
}
public static Band CreateNewBand(string key, string dataMember, string dataKeyField)
{
Band band = new Band();
band.AutoGenerateColumns = false;
band.Key = key;
band.DataMember = dataMember;
band.DataKeyFields = dataKeyField;
return band;
}
I have a listview (lvMap) with 3 columns (Map, From, To) I am trying to write a method that is called as soon as my form loads. this method should look at the listview items and and sort them only by 2 columns "Map" and "From" in ascending order, i dont want it to sort the "To" column. I have written the code below but it sorts every single column, is there a way to leave a column out of the sorting procedure. Thanks.
private void sortListViewOrder()
{
lvMappings.Sorting = SortOrder.Ascending;
lvMappings.Sort();
}
I would suggest you consult the following MSDN article, hopeful it answers your question:
http://support.microsoft.com/kb/319401
Basically you need to create a ListViewColumnSorter instance and add it to your ListView control.
From there on the article will have enough information :)
You have to do it using ListViewColumnSorter . Following KB Link has the sample code to do that.
http://support.microsoft.com/kb/319401
You can assign the column to be sorted using,
Create an instance of a ListView column sorter and assign it
// to the ListView control.
lvwColumnSorter = new ListViewColumnSorter();
this.listView1.ListViewItemSorter = lvwColumnSorter;
lvwColumnSorter.SortColumn = Column;
I needed this feature, or function, in the ListView control. The suggestion to use an Extension Class I first saw here. I tried it and it worked, but only now I can tell how to easily do it. Refer to this reference question:
How to prevent flickering in ListView when updating a single ListViewItem's text?
Step 1: Create a (separate) ControlExtensions class in your project, and paste this code:
using System.Reflection;
using System.Windows.Forms;
namespace [YourNameSpace]
{
public static class ControlExtensions
{
public static void DoubleBuffering(this Control control, bool enable)
{
var method = typeof(Control).GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(control, new object[] { ControlStyles.OptimizedDoubleBuffer, enable });
}
}
}
Step 2: Define the following in the WinForms that has the ListView:
private ListViewColumnSorter lvwColumnSorter = null;
After InitializeComponent(); section, define the following:
lvwColumnSorter = new ListViewColumnSorter();
this.lvwRunningProcesses.ListViewItemSorter = lvwColumnSorter;
lvwColumnSorter._SortModifier = ListViewColumnSorter.SortModifiers.SortByText;
Step 3: In the Form Load event, add these lines after the List View is populated:
// Sort in ascending order Column 0
lvwColumnSorter.SortColumn = 0;
lvwColumnSorter.Order = SortOrder.Ascending;
this.lvwRunningProcesses.Sort();
That's it!
I have a MyListView class that is inheriting from ListView, and is overriding OnDragDrop() (and the other necessary events to implement drag and drop). When I place two of these MyListviews on a form I am able to drag an item from one of them and drop it to the other one. This part works.
Now I want to override OnDoubleClick() to that class such that again if I place two of these MyListViews on a form and double clicked on one of them, the item gets removed from that and gets added to the other one. But I can't get my head around how to do this one.
Could you please give me some ideas? Thanks.
Don't know if you manage the sleection of the item in a particular way, but you can
or after handling double-click look for SelectedItems and act on it
or you can add a code like this using ListViewHitTestInfo class:
private override OnDoubleClick(...)
{
ListViewHitTestInfo hit = this.HitTest(e.Location);
if (hit.Item != null)
{
ListViewItem doubleClickedItem = hit.Item;
}
}
Put the logic in your host form by:
Handle double-click of first ListView
Remove from first ListView
Add to second ListView
Unless you are doing this in many different forms - it's not worth complicating it more than that.
EDIT:
If justified, centralizing can be as easy as adding a method which does the same thing (pseudocode)
public void MyForm_OnListViewDoubleClick(object sender, EventArgs e)
{
MoveListItem(firstListView, secondListView);
}
// ...
public static void MoveListItem(ListView source, ListView destination)
{
var listItem = source.SelectedItem;
source.Remove( listItem );
destination.Add( listItem );
}
Here's the answer to your title
protected override void OnDoubleClick(EventArgs e)
{
base.OnDoubleClick(e);
}
And here is the answer to your question
Using DoubleClick event on a inherited class from ListView
This just links back to your other, very similar question.
I'm trying to find a good code sample to update a database entry in my listview control. I suppose I would need to extract the ID from somewhere (some label control?). I am using LINQtoSQL to talk with the database.
protected void lvTargets_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
InventoryDataContext inventory = new InventoryDataContext();
//Target target = from target in inventory.Targets
// where target.ID == lvTargets.Items[e.ItemIndex].FindControl("ID")
// *** Not sure how to go about this ^^^
//inventory.Targets.InsertOnSubmit(target);
//inventory.SubmitChanges();
lvTargets.EditIndex = -1;
BindInventory();
}
You can get the ID from the event arguments either like
e.Keys["ID"]
e.OldValues["ID"]
depending on your situation.
Is there a straighforward way to set additional text to appear in a tooltip when a user's mouse is held over an item in a CheckedListBox?
What I would expect to be able to do in code is:
uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details
Can anyone point me in the right direction to do this? I've already found a couple of articles that involve detecting which item the mouse is currently over and creating a new tooltip instance, but this sounds a little too contrived to be the best way.
Thanks in advance.
Add a Tooltip object to your form and then add an event handler for the CheckedListBox.MouseHover that calls a method ShowToolTip();
Add MouseMove event of your CheckedListBox which has the following code:
//Make ttIndex a global integer variable to store index of item currently showing tooltip.
//Check if current location is different from item having tooltip, if so call method
if (ttIndex != checkedListBox1.IndexFromPoint(e.Location))
ShowToolTip();
Then create the ShowToolTip method:
private void ShowToolTip()
{
ttIndex = checkedListBox1.IndexFromPoint(checkedListBox1.PointToClient(MousePosition));
if (ttIndex > -1)
{
Point p = PointToClient(MousePosition);
toolTip1.ToolTipTitle = "Tooltip Title";
toolTip1.SetToolTip(checkedListBox1, checkedListBox1.Items[ttIndex].ToString());
}
}
Alternately, you could use a ListView with checkboxes instead. This control has
builtin support for tooltips.
Contrived or not; that's what there is...
I'm not aware of an easier way than you have already described (although I'd probably re-use a tooltip instance, rather than creating new all the time). If you have articles that show this, then use them - or use a 3rd party control that supports this natively (none leap to mind).
I would like to expand upon Fermin's answer in order to perhaps make his wonderful solution slightly more clear.
In the form that you're working in (likely in the .Designer.cs file), you need to add a MouseMove event handler to your CheckedListBox (Fermin originally suggested a MouseHover event handler, but this did not work for me).
this.checkedListBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.showCheckBoxToolTip);
Next, add two class attributes to your form, a ToolTip object and an integer to keep track of the last checkbox whose tool tip was shown
private ToolTip toolTip1;
private int toolTipIndex;
Finally, you need to implement the showCheckBoxToolTip() method. This method is very similar to Fermin's answer, except that I combined the event callback method with the ShowToolTip() method. Also, notice that one of the method parameters is a MouseEventArgs. This is because the MouseMove attribute requires a MouseEventHandler, which then supplies MouseEventArgs.
private void showCheckBoxToolTip(object sender, MouseEventArgs e)
{
if (toolTipIndex != this.checkedListBox.IndexFromPoint(e.Location))
{
toolTipIndex = checkedListBox.IndexFromPoint(checkedListBox.PointToClient(MousePosition));
if (toolTipIndex > -1)
{
toolTip1.SetToolTip(checkedListBox, checkedListBox.Items[toolTipIndex].ToString());
}
}
}
Run through your ListItems in your checkbox list of items and set the appropriate text as the item 'title' attribute, and it will display on hover...
foreach (ListItem item in checkBoxList.Items)
{
//Find your item here...maybe a switch statement or
//a bunch of if()'s
if(item.Value.ToString() == "item 1")
{
item.Attributes["title"] = "This tooltip will display when I hover over item 1 now, thats it!!!";
}
if(item.Value.ToString() == "item 2")
{
item.Attributes["title"] = "This tooltip will display when I hover over item 2 now, thats it!!!";
}
}