How To Hide ListView ColumnHeader? - c#

I am struggling to figure out the correct control to use for a list of predefined jobs in the included form. I currently have a ListBoxControl in the Predefined Job Name group that lists all of the predefined jobs for a marine service shop (i.e. oil change, tune up, etc...). Then, based on the item (i.e. job name) that is selected in my ListBox, I need to display the items that correspond to that job. For example, if oil change is the selected job I need to show 4 quarts oil, 1 oil filter, labor, etc...and so on.
Currently, when I load the form data I have a DAO that retrieves all of my jobs from the database using LINQ to SQL. Then I iterate over the results and put the job names into the ListBox. The problem that I am having is that there is no tag for ListBox items like there is for ListView items. So each time the user selects another item in the ListBox, I have to perform another LINQ query to get the job from the database again so that I can display its' corresponding items. If I could use a ListView and hide the column header I could set the entire job on the tag so that each time the user selects a new item I would have access to the details without having to make another call to the database. Is there a way that I can hide the column header of a ListView without hiding the entire column?

You can set the HeaderStyle member of the ListView to None.
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;

Checkout the ListView HeaderStyle property. It has the following options:
None
Nonclickable
Clickable
From MSDN:
The HeaderStyle property allows you to specify whether the column headers are visible or, if they are visible, whether they will function as clickable buttons. If the HeaderStyle property is set to ColumnHeaderStyle.None, the column headers are not displayed, although the items and subitems of the ListView control are still arranged in columns

You can also create simple object like ListItem which has two poperties: Text (string) and Tag (object). Then implement ListItem.ToString() and you can use these in the ListBox as well.
You can also check out Better ListView Express component, which is free and allows displaying items in Details view without columns. The advantage over ListBox and ListView is a native look and many extra features.

Easy way is using the ColumnWidthChanging event
private void listViewExtended1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Cancel = true;
e.NewWidth = listViewExtended1.Columns[e.ColumnIndex].Width;
}
}

I found that if you know for a fact you are not displaying the headers it may be best to set the HeaderStyle property to None, as Rajesh mentions above.
When setting in the .CS when screen initially loads the headers are displayed until screen is fully rendered.

Related

edit multiple rows selected in a GridControl in TextEdits bound to the same bindingsource

My setup:
C#.Net 4.0, Windows Forms, DevExpress 13.1.5 although I doubt its a DX issue
I have a form with a GridControl (with GridView) on the top and a detail area that holds TextEdits and other edits in a LayoutControl below.
Both the grid and the edits below are bound to the properties of the objects contained in a list in the binding source.
The grid is set to ReadOnly, MultiSelect, RowSelect and all its columns are set to ReadOnly, not focusable.
Editing is only happening in the detail area below.
The behavior I want to create:
When multiple rows are selected in the grid the edits below should show the following:
the value of field in question is the same in all selected rows -> show the value
the value of the field in question differs between the rows -> show nothing
if the user writes into the TextEdit while multiple rows are selected:
the value of the edit should update the values of the same field of all the selected rows
Where I am with this:
I'm working on a solution by building a custom BindingSource that would be aware of the selection. It would bind the list of object to the grid and a single object that is not part of the list to the edits. Depending on the selection I would set the properties of that single object or forward its changes to the selected objects in the list.
I got that working for a single property with 2 binding sources and would now extend it to use reflection to do this for all of the public properties. I also want to encapsulate the whole behavior into a class that looks and acts like BindingSource just with that added behavior.
The question:
Is there a simpler way to achieve this? Does something already exist which can do this that I overlooked in either .Net or DevExpress? Are there traps to my approach that I should consider or why I should go about this totally differently?
I think that you can achieve your goal in a simpler manner:
Just bind a single BindingSource with all the data that you need to your grid. That should display the data.
Then, bind the required fields from that same BS do the edits through the DataBindings propriety.
You can then implement a save object (through a control or programatically) so the changes made in the edits are shown in the grid.
To check the grid values, you can use:
//get the handles of the rows
gridView.GetSelectedRows();
//get the value of the desirable cells
gridView.GetRowCellValue(handle, column);
Also, in future projects, consider using the Entity Framework to construct a data-aware model and custom objects based on the elements of your Database.
Hope this helped!

Datagrid on demand load off

I have a SDK:DATAGRID with 20 columns or so, when it opens up it only shows four fields/columns. Which is what I want and how I designed it
Basically I'm grabbing information based on the user click - EXAMPLE:
OWNERNAME.Text = ((TextBlock)EPICGrid.Columns[1].GetCellContent(EPICGrid.SelectedItem)).Text;
and/or
OWNERNAME2.Text = ((TextBlock)EPICGrid.Columns[16].GetCellContent(EPICGrid.SelectedItem)).Text;
What I'm running into it doesn't grab the information in the cell unless if I scroll and show the column so I can only grab the first 4 columns of data because they show when the grid becomes visible.
I can't grab data from columns 5 -20 unless I scoll over and make those columns visible. They don't have to be visible during the click...it just seems like the data doesn't really load until I view the column.
I guess I should say the first record/row loads all the data/cells/columns and I can grab any data from the first record but the problem happens with records 2 - *.
Just to clarify - my issue is not a visibility of my columns or rows. My issue is the SDK DataGrid seems like it is loading the data on demand. So if the column is not in view at one point or another the information in the cell is not available.
I don't want to show all columns and I don't want to give the user the ability to see all columns so I want to disable the scroll bars but when a user clicks on a certain row I need to grab information in certain cells and since the column is not load yet the information is not there.
How do I turn the feature load on demand off?
I did a search and found out that someone had a similar problem with rows loading and the suggestion was setting the VirtualizingStackPanel.VirtualizationMode = Standard
It almost like the problem is stemmed from VirtualizingStackPanel.VirtualizationMode but I set this property to standard and recycle and no luck.
Here's definition:
By default, a VirtualizingStackPanel creates an item container for
each visible item and discards it when it is no longer needed (such as
when the item is scrolled out of view). When an ItemsControl contains
a lot of items, the process of creating and discarding item containers
can negatively affect performance. When
VirtualizingStackPanel.VirtualizationMode is set to Recycling, the
VirtualizingStackPanel reuses item containers instead of creating a
new one each time.
On initial load, if the cell is not visible I can not grab the cells
content (unless it is the first record/row). Once and after the cell /
column is visible then the information is available.
I think you are expected to deal with the data that the row is bound to directly and not pull the data out of the controls. This makes sense since it is two way data binding so the data is updated as you are changing it (assuming it implements the INotifyPropertyChanged Interface).
An example would be where a datagrid is bound to a collection of type MyEntity.
private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.DataGrid1.SelectedItem == null)
return;
MyEntity myEntity = (MyEntity)this.DataGrid1.SelectedItem;
// at this point you have the (updated) data the row is bound to.
MessageBox.Show("You Selected: " + myEntity.name);
...
Another example is where there is a button on each row. The code to process when a button is clicked looks something like:
private void btnProcessEntity_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
MyEntity myEntity = btn.DataContext as MyEntity;
// clicking a button in a row doesn't select the row, so select it.
this.DataGrid1.SelectedItem = myEntity;
MessageBox.Show("Will Process: " + myEntity.name);
...
}
If you are not familiar with some of the technologies that normally are used with Silverlight check out these Video Tutorials. It is VB.Net, but the code is really not the focus - it is focused on a Silverlight application architecture. I would start with "Intro to SL4 and WCF Ria Services" and then view one of the ones on MVVM.

Is there a textboxlist control available somewhere?

There are ASP controls such as radiobuttonlist and checkboxlist and you can databind them to a database query. It's great for creating dynamic lists with user interaction. What I'm trying to do is generate a list of textboxes in the same fashion. A list of textboxes that behave the same way.
The object is to have a checkboxlist that is generated via datasource/database. When the user is finished selecting items from this list, they click a button. That list hides (using jquery) and a new list is created based on their selections. However, the new list is now a list of their selections accompanied by an empty textbox. The user fills in the textboxes for each entry and submits again which commits it to a database.
SO:
checkbox - description
checkbox - description
checkbox - description
checkbox - description
Becomes:
Description - Textbox
Description - Textbox
The reason that I'm looking for a list-type control is so that I can ultimately loop through it for submission to the database using linq. Does that make sense? My real question is if there is a control like this yet. I gave the full description in case someone has any other ideas, short of creating a custom control.
There's nothing out of the box that does what you describe no. But you can still loop through controls. I would put your form controls inside of an asp:Panel or a div with runat="server" and use something like the following code to cycle through them as you described.
foreach(Control ctl in myPanel.Controls)
{
//check control type and handle
if (ctl is TextBox)
{
//handle the control and its value here
}
}
asp:ListBox has a property named SelectionMode, which can be set to SelectionMode="Multiple" and allows you to select items you want. This is not exactly what you need but it's a simple solution.
After the selection is made in checkboxlist, make a postback to server. Here create a datatable with two columns (description & text). For every selected item in the checkboxlist add a row to this table and bind it to a gridview control. Here 'text' column will be always empty. Configure the gridview to use template column with a textbox in the itemtemplate

Editable GridView Distinct Drop Down LIsts

I have a simple app I am messing around with its a basic Master/Details layout.
The details panel is actually a tab panel and on one of the tab panels it has a GridView. Within that grid view it shows the "current" in database information with all cells as read only.
alt text http://lh4.ggpht.com/_JU1W2P96pD4/TAeonNNYXgI/AAAAAAAAAq0/Y_-Kse7VObE/ExampleA.jpg
I then have an add button that inserts a row into the GriView and allows the user to enter some information. The first item in my GridView is a DropDownList, which is populated from an ObjectDataSource. This drop down is basically my unique index and there can only be one selected value per GridView.
alt text http://lh3.ggpht.com/_JU1W2P96pD4/TAeonIF3DdI/AAAAAAAAAq4/JhfOTsHgsf8/ExampleWithDropDown.png
What is the best way to remove the values from the list that are already in the GridView? Do I just need to remove the data source and add a OnDataBinding method that iterates through the grid view and generates a valid list of values?
I can't use a service method because if the user adds two rows they would have the option to insert duplicates description types.
Just want to make sure there is not a better way to do this.
Keep the object datasource, which I am assuming is an IEnumerable object, in a Session variable. When someone selects a certain value remove that value from the list in the session variable. Whenever they activate the form where the drop down list is displayed simply rebind the control to the list in the session variable. It will be easier than looping through the grid every time the user adds an entry.

Display ASP.NET GridView inside a selected row in another GridView

I have been given a mockup that I do not know is possible to code in ASP.NET without being a real html and javascript wizard.
I want a GridView that when a row is selected, the selected row expands and below the selected row a panel of additional information is shown, which would also include another small GridView. The idea is this would all be in-line. So if the user selected row 4, then the additional information would appear below row 4 and then after the additional information the parent GridView would continue with row 5.
Ultimately I would want to do a multi-select type of set up, but first I need to figure out if this is even possible. Also, the solution must be 508 Compliant
The one solution I considered was using only one "column". Then I would put all my fields in the ItemTemplate, and my detail panel content in the EditItemTemplate and instead of selecting the row, set it to edit mode. The problem with this solution is I lose the functionality of multiple columns if I throw everything in one huge ItemTemplate.
Any and all suggestions or ideas are appreciated.
What you're describing would be best fulfilled with a ListView control. It takes a little more templating work to set up than a grid view, but you have much more control over it and you can emulate the look of a GridView. You would set your Selected Item template to contain another ListView (or GridView) thats bound to your detailed data.
I've done this using a gridview inside a ListView and using ajaxcontroltoolkit collapsible panel
Your parent list would be a listview that would have 2 table rows for each item, on the first row your parent column, on the second row use colspan and add a gridview wrapped on a collapsible panel

Categories

Resources