How to add an image to ListView column header? - c#

It should be easy, right?
Have a listview, add an imagelist, add images to the imagelist, assign image index to the column you want.
But, it doesn't work.
Microsoft article states that it is a known problem in .NET 1.1.
But has it been fixed since?

You still have to use Interop. I suggest you to use the example given in the article.

I did like this
1)made imagelist1
2)set the listviewlarge=imagelist1 & samallImagelist = imagelist1
3)write to form initilaize area
this.Columname0.ImageIndex = 0;
this.Columname1.ImageIndex = 1;
its work.

Related

Using ClosedXML how to adjust row height to content?

I create cell with text. After that I set WrapText property and column width.
var cell = worksheet.Cell("A1");
cell.Style.Alignment.WrapText = true;
cell.SetValue("This is very long text");
worksheet.Column(1).Width = 10;
worksheet.Rows().AdjustToContents();
The text has been moved by words, but row height is not changed. How to adjust row height to cell content?
There are many ways to achieve this.
Don't use wrap or shrink properties on cell values rather include this line just before saving your excel
ws.Columns().AdjustToContents();
Another way is to make use of Allignment property
IXLRange titleRange = ws.Range("B2:AA2");
titleRange.Cells().Style
.Alignment.SetWrapText(true); // Its single statement
Hope it helps!!
It works when you remove the worksheet.Rows().AdjustToContents();.
Autofitting sometimes needs more of a trial and error approach ...
The following code worked for me.
IXLRange contents = ws.Range("A1:A50");
contents.Style.Alignment.WrapText = true;
You can also AdjustToContents on Specific range of cells.
worksheet.Columns(2, 20).AdjustToContents();
I think this is a bug of ClosedXML.
enter link description here
ws.Row(1).AdjustToContents();
ws.Row(1).ClearHeight();
In my case it works.
Version: 0.95.4

WPF Make layout dynamically

I want to make layout dynamically.
For example, When I drag and drop a image, 1 image appears on the box.
When I drag and drop another image, box divide into 2 box (dynamically divide into two).
My question is, what layout should I use (stack panel, grid, or something else) and How to I make layout dynamically using code?
I know question is a little vague but I'm not so good at WPF so please understand Thx.
I would use a GridView and so you can add column or row.
DataGridViewTextBoxColumn trackPositionTextBox = new DataGridViewTextBoxColumn();
trackPositionTextBox.HeaderText = "Track Postion";
trackPositionTextBox.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewSamples.Columns.Add(trackPositionTextBox);
That's to add a Column in a DataGridView.
dataGridViewSamples.Row.Add()
That's to add a row.
I'm also not the best in wpf, but I hope it was helpful.
If you don't need any animation, you could simple add new columns and rows to your WPF-Grid, while drop an image.
Maybe this help you: How to add rows and columns to a WPF Grid programmatically

How to add a Datagridview into a Scatterviewitem?

I am trying to display the contents of different tables dynamically using scatterview, is there an easy way to do that. Right now I have the results of a query in DatagridView and I want to add it to a ScatterViewItem. I tried directly assigning, however I must be doing something wrong here. Do I need to bind it to the xaml code?
dgv = QueryResult();
svi.Content = dgv.DataSource;
The answer for this question was already there, my mistake I did not search that well.
The last post in :
Can I programmatically add a row to a WPF datagrid?
Moderators please flag appropriately.
Thanks

Enabling and disabling of columns in Infragistics UltraGrid

I have an Infragistics grid and I want to disable and enable some columns based upon some requirement. I have read some articles that say to use AllowUpdate = DefaultableBoolean.True but it did not work for me.
I suppose that when you talk of disabled columns you mean disable editing in these columns.
Also you don't specify the language, so I will use C#
UltraGridColumn c = grdWork.DisplayLayout.Bands[0].Columns["YourColumnName"];
c.CellActivation = Activation.NoEdit;
c.CellClickAction = CellClickAction.CellSelect;
The property CellActivation could also be set to Activation.Disabled or Activation.ActivateOnly.
The property CellClickAction allows to set an appropriate selection status for the cell clicked. You could use CellSelect or RowSelect. (This last one, to mimic the behavior of a ListBox)
As usual, the real difficulty is to find the correct property. Then Intellisense will give you a quick and fair explanation of the meaning of these values.
If you just want to show and hide the columns as needed then you can try the following.
UltraGrid myGrid = new UltraGrid();
//Bind to your data here
myGrid.DisplayLayout.Bands[0].Columns["ColumnName"].Hidden = true;

How to refresh DataGridView cells style

I have this simple piece of code on a windows form containing said DataGridView (dgvStatsTable) :
public void LoadStatsTable(DataTable statsTable)
{
dgvStatsTable.DataSource = statsTable;
var smallFont = new Font(dgvStatsTable.Font.FontFamily, dgvStatsTable.Font.Size * 0.67f);
dgvStatsTable.Rows[0].Cells[0].Style.Font = smallFont;
dgvStatsTable.InvalidateCell(0, 0);
//dgvStatsTable.Invalidate();
dgvStatsTable.Refresh();
}
Once that function has been called, my DataGridView contains the correct data to see.
However, that style change that I wanted is not showing (first cell in top-right corner has to have smaller text).
Why?
Is it because the table is set to a DataSource rather than building rows and columns?
Thanks!
The Solution to the problem was to write a handler for the DataGridView.CellFormatting Event
found in this MSDN article in the Setting Styles Dynamically section.
Here is a very nice answer from MSDN network, it appears that in order to have greater control you will need to override some functions.
http://msdn.microsoft.com/en-us/library/7fb61s43(VS.80).aspx

Categories

Resources