I am doing a windows mobile application 6.1.
I dragged in a listview and went to columns and added columns to my list view. When I run the listview they do not show up.
I then tried to add them through C# code on page load with the follow code.
ColumnHeader header = new ColumnHeader();
header.Text = "gkgag";
header.Width = 100;
header.TextAlign = HorizontalAlignment.Center;
listView1.Columns.Add(header);
this does not work either. Why don't they show up?
You must use detailed view for column headers to be visible.
listView1.View = View.Details;
If that´s not the problem, column headers might be hidden behind windows systembar.
Related
I have added a filter to my datagridview using DataGridViewAutoFilterColumnHeaderCell class. i did the following
foreach (DataGridViewColumn col in pDGV.Columns){
col.HeaderCell = new DataGridViewAutoFilterColumnHeaderCell(col.HeaderCell);
col.SortMode = DataGridViewColumnSortMode.NotSortable;
}
I have got the filter working correctly but I have one small niggling issue with the datagridview, the filter button doesnt show until I click another headercell.
How can I get to show the filter correctly as soon as the code to apply it runs? I have tried to call things like datagridview.invalidate() and datagridview.refresh() in the hope of refreshing the header row but that doesn't seem to work.
Regards
Amarino
I have 4 Dev Express Grid Columns (Two are not visible)
I'am trying to make the visible Columns like :
this.DataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
I tried the following :
gridView2.Columns["MyColumnB"].BestFit();
It works fine but is there is anyway so It dosen't get Width more then GridControl and don't get that Horizental ScrollBar ?
Sorry , Fixed using :
gridView2.OptionsView.ColumnAutoWidth = true;
Try this code which will tell the grid view to never display the horizontal scroll bar, then create the best fit columns for the entire grid view, instead of just doing so for a specific column.
gridView2.HorzScrollVisibility = ScrollVisibility.Never;
gridView2.BestFitColumns();
I am using WindowsFormHost so as to be able to use a gridview in my WPF application
(started with this ,How to instantiate a Datagridview(in code behind)).
And proceeded as
public WindowsFormsHost HOST = new WindowsFormsHost();
my gridview as
System.Windows.Forms.DataGridView gridview = new System.Windows.Forms.DataGridView();
(do not forget the references, follow here- http://www.c-sharpcorner.com/uploadfile/mahesh/using-windows-forms-controls-in-wpf/)
I fill it with a datatable as
table = new System.Data.DataTable();
table.Columns.Add("Object ID");
foreach (string column in columns)
{
table.Columns.Add(column);
}
foreach (string row in rows)
{
drow = table.NewRow();
tit = row.Substring(0, row.IndexOf('$'));
drow[0] = tit.IndexOf('&') > -1 ? tit.Substring(tit.IndexOf('&') + 1) : tit;
table.Rows.Add(drow);
}
//making the native control known to the WPF application
HOST.Child = gridview;
//Displaying the column headers of the listbox(assigned above).
gridview.DataSource = table.DefaultView;
However when I add the gridview to my WPF window as
this.Children.Add(gridview); //error at this line
I get an error saying
cannot convert from 'System.Windows.Forms.DataGridView' to 'System.Windows.UIElement'
Why so ?
I mean what may I do to rectify this ?
DataGridView is a WinForms control. So you can't directly add that to WPF Control's child. Instead add the WindowsFormsHost instance as follows:
RootGrid.Children.Add(HOST);
Is this question and current answer serious??? Why on earth would you want to import the WindowsForms dll and add a CPU intensive WindowsFormsHost element to your WPF application just so that you can use a DataGridView control? You'll find that it's much better just using the equivalent WPF control: DataGrid
You can find out all about the DataGrid class by viewing the DataGrid class page on MSDN. This page has a detailed description and code examples to help you to use the control. Furthermore, the WPF DataGrid Practical Examples page on CodeProject has detailed examples on how to do just about anything that one might want to do with the DataGrid control.
Guys I am posting what did the trick for me for future visitors.
Instead of adding the gridview I added the HOST to the window and it worked.
this.Children.Add(HOST);
SOLVED HERE :Using windows forms controls on a WPF page
When using Silverlight/WPF Datagrid and you add a new row to the existing collection, how can I jump into a specific cell's edit mode in order to hint to the user that this field needs to be filled out right away?
Many Thanks,
This is how I was able to make it work in SL 5 RC.
dg.ItemsSource.Add(data);
dg.SelectedItem = data; //set SelectedItem to the new object
dg.ScrollIntoView(data, dg.Columns[0]); //scroll row into view, for long lists, setting it to start with the first column
dg.Focus(); //required in my case because contextmenu click was not setting focus back to datagrid
dg.BeginEdit(); //this starts the edit, this works because we set SelectedItem above
Hope this helps.
In Silverlight 4 it is:
dg.SelectedItem = data;
dg.CurrentColumn = dg.Columns[1]; // You have to use this line instead
dg.Focus();
dg.BeginEdit();
I need to populate a list that has 3 columns.
First: Icon Image.
Second: A string.
Third: A string.
I started to wire up a DataGridView and it seem awfully large and powerful for my needs. I am not interested in displaying data in a grid similar to a spreadsheet and I do not require all the functionality that comes with this control. Is there a better alternative?
Thanks!
You could go for the ListView in View.Details view, as this is similar to the view that you see in Windows Explorer when in Details view.
Create a form and place on it an ImageList and a ListView named imageList1 and listView1 respectively. Then place the following code into the forms load method:
listView1.Columns.Add("Image");
listView1.Columns.Add("Text1");
listView1.Columns.Add("Text2");
listView1.SmallImageList = imageList1;
var icon = Icon.ExtractAssociatedIcon(#"c:\windows\explorer.exe");
imageList1.Images.Add(icon);
var item = new ListViewItem();
item.ImageIndex = 0;
var subItem1 = new ListViewItem.ListViewSubItem();
subItem1.Text = "Text 1";
var subItem2 = new ListViewItem.ListViewSubItem();
subItem2.Text = "Text 2";
item.SubItems.Add(subItem1);
item.SubItems.Add(subItem2);
listView1.Items.Add(item);
The code really couldn't hurt for some tidying up, but it calls out quite explicitly what it's doing and should hopefully make it quite clear how to use a ListView for this purpose.
You could try ListView. You'll want to use the Columns property and Details mode.