I've got a ListView with several columns. The ListView's SmallImageList contains three icons; an up-arrow, a down-arrow and a folder icon. When one of the column-headers is clicked, the list is sorted by that value, and to illustrate this, an icon is inserted into the header showing the up or downarrow from its SmallImageList. This works fine.
My problem is that when clicking on a new column to sort by, the icon in the old header should dissapear, but it doesn't. Instead, a folder-icon is inserted. This happens each time a new header is clicked, so eventually all headers are filled with folder-icons.
Whenever a column is clicked, all the columns are iterated through and their ImageKey is set to an empty string, and later replaced by the ImageKey for the arrows, if it was the clicked column. The empty string apparantly loads the folder icon.
for (int i = 0; i < m_LVCases.Columns.Count; i++)
{
m_LVCases.Columns[i].ImageKey = "";
if (i == e.Column)
{
if (m_ListViewColumnSorter.Order == SortOrder.Ascending)
m_LVCases.Columns[i].ImageKey = SortOrder.Ascending.ToString();
else if (m_ListViewColumnSorter.Order == SortOrder.Descending)
m_LVCases.Columns[i].ImageKey = SortOrder.Descending.ToString();
}
}
I can't post screenshots yet, as I don't have enough reputation. Does anybody have a solution to completely remove an icon from a column-header, or do I have to do some magic to display this in another way?
--Edit-- This is a project that I took over, so I'm trying to piece things together. I found out that setting the ImageKey for the column to null, resulted in all the headers (except the one clicked) got the folder icon, which is very strange to me. I tried adding a new icon, with only transparent color on it. This did in fact clear all the icons, but it left a gap where the icon should have been. Is there a way to place the icon-allignment to the right instead, so it won't move the header text for every column?
There's a pretty clean example of this in the MSDN reference here
What you're doing is very different, but what might help you is to set the .visible property of the column sortimage to false for the other columns.
I fixed the problem myself. I was trying to place the icons to the right of the text instead, but by setting the column's TextAlign property to anything just after havning cleared the imageKey, the folder-icons stopped appearing.
So I removed the symptoms, but I still don't know what the disease was.
Related
This issue occurred after update.
Cell without initial value after click not change state, i.e. they look like disable, but when I start fill cell start expanding.
Gif
But if fill cell by initial value, space for example, it's work fine.
Has anyone encountered a similar problem and how did you solve it? Case with a space is not very pleasant.
In the new version of FastReport, the TextRenderType property has been added for text fields. Since the cell is inherited from the text field, then this property is available to it.
Setting the value to HtmlParagraph solves this problem, but when exporting to excel turns some cells into pictures.
If there are many cells and manually changing the value is problematic, you can use the code:
var tableCells =
report.AllObjects.ToArray().Where(item => item.GetType() == typeof(TableCell)).Cast<TableCell>();
foreach (var tableCell in tableCells)
{
tableCell.TextRenderType = TextRenderType.HtmlParagraph;
}
But execute it before the Prepare() method and after loading the document template.
I have DataGridView with Four columns.
1st column contains "Text",
2nd, 3rd and 4rt column contains Bit Image.
Now this image are conditionally get rendered inside the columns and if condition is false it will contain "null" i.e. nothing in that column. However this blank column is part of Tab key, means when user navigate using Tab key in the grid, cursor traverse across all the column irrespective of column contains anything or not in it.
I would like to traverse cursor only to the column which contains value with in it. So how can I achieved this?
Following are the approaches I tried -
1. I filled all the column with respective images by removing the condition. now all the columns have some image in it, but I am unable to Enable/Disable those image conditionally. and because of that this all images are actionable and user can perform the operation which it should not. And when I applied Visible true/False so that it will apply across all rows for that column index and resultant the valid cell also invisible.
2. I placed button with in that column and tried to applied that bit image to that button and tried to enable/disable button as button has the property. but Bit Image is not getting applied to button and when I assign gridCell.value = btn; it will throw error since it is not text it is complete control. So not valid approach.
3. Using ProcessCmdKey() Method group, but not acceptable approach, though it has started performing as expected.
Please find the screen shot for more detail.enter image description here
Layout images and behaviord0sAI.png
The title may be a bit confusing, and I'll try my best in trying to explain my problem.
I have a horizontally scrollable datagridview and when I click a button on the menu bar, I want the datagridview to move the view to the specified column, while still having all columns still visible.
So For example I click on Fish, and then the datagridview should scroll/position itself to the first mention of Fish in the columns to show a section of the view all related to Fish, while still maintaining all other columns not related to Fish and viewable.
What I would like to know is, is the moving of the position of the view possible to do? I didn't know what to search up, and more or less the results of the search included re-ordering of the columns, which I do not want.
For a DataGridView with windows form --- give your cell to Particuler Id.
Like you want to assign a one column with Fish then
row.Cells["Name"].Value = Fish.Id;
and then on click event give focus to this id.
Note:- for a better solution post your question with your code.
thanks
Replace fish to your search text and try it.
List<DataGridViewColumn> Cols = dataGridView1.Columns.Cast<DataGridViewColumn>().Where(c => c.HeaderText.Contains("fish")).ToList();
if (Cols.Count > 0)
{
dataGridView1.FirstDisplayedScrollingColumnIndex = Cols[0].Index;
}
Above code will scroll down datagridview horizontally to show searched text in column names.
I'm using ObjectListView with C# and .Net 4.0. I wrote code that reloads the listview and then re-selects the last selected index.
The re-selection code is quite simple:
olvListView.SelectedIndex = i;
This appears to work, because the item is selected. However, if I then click the up or down arrow, the selection jumps up to the second row (no matter what row I selected), suggesting that the selection was actually set on the first row, no matter what was the value of i.
What am I doing wrong here?
The underlying ListView Control distinguishes between 'selection' and 'focus'.
olvListView.SelectedIndex = i; changes the selection but not the focus. But the focused row is the one that the keyboard input relates to.
Either change the focus the as well
olvListView.SelectedIndex = i;
olvListView.FocusedItem = olvListView.SelectedItems[0];
or call
olvListView.SelectObject(aModelObject);
The second solution would be the preferred way to select an item when working with OLV, however you say you "wrote code that reloads the listview", so the reference to the original item is probably different. Maybe you should just refresh the items that changed, instead of reloading everything. That way you could preserve the selection.
Example if your olv have datasource from "class_z.list" and foreach have only one result.
foreach(class_z a in class_z.list.Where(x=>x.id==id_value))
{
olv.SelectedObject = z;
}
As a question similar to this question, I also have an application with a DataGridView on it. I would like to position the rows such that a specific row is at the bottom of the visible part of the list.
This is in response to a button click that moves a row down by one. I want to maintain the selection on the row I'm moving (I already have this part working). If there are lots of rows, the selected row might move below the visible area. I want to scroll down until it's at the bottom of the visible area.
There does not appear to be a LastDisplayedScrollingRowIndex companion to FirstDisplayedScrollingRowIndex.
Any ideas? Thanks.
As my own guess, I think I need to use FirstDisplayedScrollingRowIndex and the number of rows visible in the DataGridView to calculate the new FirstDisplayedScrollingRowIndex. Maybe I just need to find out what the NumberOfVisibleRows property is called?
Found it. DisplayedRowCount:
if (dataGridView.FirstDisplayedScrollingRowIndex + dataGridView.DisplayedRowCount(false) <= selectedRowIndex)
{
dataGridView.FirstDisplayedScrollingRowIndex =
selectedRowIndex - dataGridView.DisplayedRowCount(false) + 1;
}
Code tested and working in my own project.
The DisplayedRowCount method will tell you how many rows are displayed on screen. Set the parameter value to true to include partial rows.
var displayedRows = myDataGridView.DisplayedRowCount(false);