Hyperlink C1Flexgrid Column Data in silverlight - c#

I am using Component one FlexGrid in my silverlight Application and it is autogenerating columns in the grid. I want to make one of the column's data behave as a clickable hyperlink. Any help on this problem would be greatly appreciated.

I have figured out a way to add hyperlink cell in C1FlexGrid.
One should extend CellFactory Class and inside the class
override method CreateCellContent(C1FlexGrid grid, Border bdr, CellRange range)
and write something like this:
public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange range)
{
//Ofcourse One should figure out first the col in which they want to
//add the cell
var width = GetWidthForHyperlinkControl((string)grid[range.Row, range.Column]);
var cell = new HyperlinkControl
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
Width = width,
Height = 16,
NavigateUri = null,
IsTabStop = false,
Content = (string)grid[range.Row, range.Column]
};
}

The sample projects for ComponentOne FlexGrid include a Hyperlink sample. Should be part of your installed items.
If not, you can also access it via the ComponentOne website.
Essentially, you set up a style for the hyperlink cells/columns and apply it. You can use OwnerDrawCell events to do it, as the example shows.

Related

CollectionView cell height is not automatically resizing

So I am encountering some issues with a UICollectionView I have in my Xamarin iOS project.
The cells for the CollectionView are not expanding with the label in them. The label in the cell has lines set to 0 and the following constraints:
(top, bottom, leading, trailing) to superview
Height >= 10
In my ViewDidLoad() I setup the CollectionView as follows:
var source = new CustomCollectionViewSource(collectionView);
collectionView.Source = source;
collectionView.SetCollectionViewLayout(new UICollectionViewFlowLayout()
{
ScrollDirection = UICollectionViewScrollDirection.Vertical,
EstimatedItemSize = new CGSize(collectionView.Frame.Width, 10)
}, false);
var set = this.CreateBindingSet<MainViewController, MainViewModel>();
set.Bind(source).For(v => v.ItemsSource).To(vm => vm.DataSource);
set.Apply();
and my CollectionViewSource
public class CustomCollectionViewSource : MvxCollectionViewSource
{
public IList<Item> Messages { get; set; }
public override void ReloadData()
{
var list = (ItemsSource as IEnumerable<Item>).ToArray();
Messages = list;
}
public CustomCollectionViewSource(UICollectionView collectionView) : base(collectionView)
{
collectionView.RegisterNibForCell(CustomCollectionViewCell.Nib, CustomCollectionViewCell.Key);
}
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
var cell = collectionView.DequeueReusableCell(CustomCollectionViewCell.Key, indexPath) as CustomCollectionViewCell;
cell.DataContext = Messages.ElementAtOrDefault(indexPath.Row);
return cell;
}
}
I am trying to have the cells be the width of the collection view and for the height to be flexible; however, whenever I populate the cells, I always get something like this:
The cells are cutoff and have an ellipses at the end. I've read online that the constraints must be right to dynamically resize, so is there something I'm missing?
I also read that to get a calculated height for each cell I can load the nib of the cell, populate it, then set the size manually in a custom UICollectionViewDelegate. Cool idea, but I could find any working examples for Xamarin iOS.
Please let me know if there is something I'm missing or any other info you require. Thanks in advance!
1.Make your label support multiple lines by
textLabel.LineBreakMode = UILineBreakMode.WordWrap;
textLabel.Lines = 0;
2.Set the cell estimated height
cell.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
Things to note:
To define the cell’s height, you need an unbroken chain of
constraints and views (with defined heights) to fill the area
between the content view’s top edge and its bottom edge.
If your views have intrinsic content heights, the system uses those
values. If not, you must add the appropriate height constraints,
either to the views or to the content view itself.

add new line in gridview cell

I have a gridview that display grade, but i don't want to display in one line. What i have tried is like this picture it became wrap text.
the code
gridView_Attendees.Columns["grade"].Caption = "Grade";
gridView_Attendees.Columns["grade"].Width = 150;
gridView_Attendees.Columns["grade"].OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
gridView_Attendees.OptionsView.RowAutoHeight = true;
gridView_Attendees.Columns["grade"].AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
RepositoryItemMemoEdit memoEdit = new RepositoryItemMemoEdit();
memoEdit.ReadOnly = true;
memoEdit.AutoHeight = true;
memoEdit.WordWrap = true;
gridView_Attendees.GridControl.RepositoryItems.Add(memoEdit);
gridView_Attendees.Columns["grade"].ColumnEdit = memoEdit;
what i want is add new line to break into 2 lines, precisely before text Technique. like this pic
To achieve your goal, assign MemoEdit editor as a cell in-place editor
and set the View's OptionsView.RowAutoHeight property to True.
You have already used this approach but it does not work as you want so you can emulate the desired behavior by handling the GridView.CustomDrawCell event: draw the multi-line text and set the e.Handled property to true to prevent the default painting of the grid's cell's content. In this case, you need to increase the grid's row height. To do it, set the GridView.RowHeight property or handle the GridView.CalcRowHeight event , to set the individual height for the every grid's row (in this case, the GridView.OptionsView.RowAutoHeight property should be set to false).
References:
Display multi-line text in gridview cell
Multi line text indentation in XtraGrid memoedit cell
gridview cell display multiline text

Can a C# DataGridView cell be both Multiline and single line?

I'm building a DataGridView dynamically, and the textboxes potentially have an AutoComplete custom source associated with them. Under some circumstances, when I set textbox.Multiline to true, I get the following effect. If I'm not actively editing the cell, it looks like this:
However, if I try to edit the cell, it looks like this:
If I move the cursor around this edit mode cell, focus hops out of the cell entirely, instead of moving the text or expanding the cell height. It looks as if it's trying to be in multiline and single line mode at the same time, but I'm not sure.
Any thoughts?
I found a solution - not a root cause. In EditingControlShowing, I do the following:
textBox.Dock = textBox.Multiline ? DockStyle.Fill : DockStyle.None;
where I've set textBox = (TextBox) e.Control;
It's a sledgehammer solution, but it works.
Lets give a name to the DataGridView object: dgv,
So On dgv_CellEnter event add following lines
int idxcol = dgv.Columns["YourColumnName"].Index;
if (e.ColumnIndex == idxcol)
dgv.Columns[idxcol].DefaultCellStyle.WrapMode = DataGridViewTriState.False;
and on dgv_CellLeave event add the following lines
int idxcol = dgv.Columns["YourColumnName"].Index;
if (e.ColumnIndex == idxcol )
{
dgv.Columns[e.ColumnIndex].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
}

DataGridView column auto adjust width and resizable

I am wondering if it is possible to have a dataGridView column to adjust automatically its width to its content and at the same time being resizable by the user ?
Here what i have tried so far :
dataGridView.AllowUserToResizeColumns = true;
dataGridView.Columns[0].AutoSizeMode=DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView.Columns[0].Resizable = DataGridViewTriState.True;
But, I am still unable to resize the column size manually.
If anyone already faced this issue or have any idea let me know.
Thanks.
I finally find a way to do what I wanted.
The idea is to
let the dataGridView resize the columns itself to fit the content, and then
change theAutoSizeColumnMode and set the width with the value you just stored.
Here is the code:
dataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
int widthCol = dataGridView.Columns[i].Width;
dataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
dataGridView.Columns[i].Width = widthCol;
Hope this will help.
Building on the code above to iterate it for all columns and also auto adjust the width of the DataGridView
//initiate a counter
int totalWidth = 0;
//Auto Resize the columns to fit the data
foreach (DataGridViewColumn column in mydataGridView.Columns)
{
mydataGridView.Columns[column.Index].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
int widthCol = mydataGridView.Columns[column.Index].Width;
mydataGridView.Columns[column.Index].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
mydataGridView.Columns[column.Index].Width = widthCol;
totalWidth = totalWidth + widthCol;
}
//the selector on the left of the DataGridView is about 45 in width
mydataGridView.Width = totalWidth + 45;
You can just use this simple code:
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
After setting datasource. It will set the width and allow resize.
The thing that is not obvious (it was not to me) is that use of AutoSizeMode means we want the size to be managed, so that implies that the user would not (cannot) do a resize. So what I have tried and it seems to work is to use DataGridView.AutoResizeColumn (note that it does a one-time resize) for each column or most columns then set DataGridView.AllowUserToResizeColumns to true. There are probably other variations but the important thing is that use of AutoSizeMode is mutually exclusive with allowing the user to do a resize.
Thanks for the solution above (To iterate through the DataGridView.Columns, change AutoSizeMode to a valid one, collect width value and set it back after change AutoSizeMode to DataGridViewAutoSizeColumnMode.None).
I struggled with it, and noticed it won't work whenever it is called from the class constructor or any line before Form.Show() or Form.ShowDialog(). So I put this code snippet in the Form.Shown event and this works for me.
My transformed code, reguardless of whatever DataGridView.AutoSizeColumnsMode set before, I use DataGridViewColumn.GetPreferredWidth() instead of changing DataGridViewColumn.AutoSizeMode and set the width value immediately, then change DataGridView.AutoSizeColumnsMode once:
private void form_Shown(object sender, EventArgs e)
{
foreach (DataGridViewColumn c in dataGridView.Columns)
c.Width = c.GetPreferredWidth(DataGridViewAutoSizeColumnMode.DisplayedCells, true);
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
}
Be sure to set
dataGridView.AllowUserToResizeColumns = true;
I don't know how come this only works after the form is shown.
Simple solution: Either bound filed or template filed. you can use ItemStyle-Width
<asp:BoundField DataField="SSSS" HeaderText="XXX" ItemStyle-Width="125px"/>
<asp:TemplateField HeaderText="EEEE" ItemStyle-Width="100px">

Unable to display the full image in datagridview cell

I have data grid view with columns product name and product image and I am populating these values coming from database...
i am using winforms desktop application.....
my problem is I am not able to showing the image in datagridview cell properly ..see the diagram below
i want to display this image in actual product image column for every cell in that column
this task is very simple in webforms by using datalist control but i dont know how to display full image in grid view cell
can any one help on this....
many thanks.......
and this is where i am binding the datagridview by using linq query..
private void EquipmentFinder_Load(object sender, EventArgs e)
{
var products = from prods in abc.products
select new
{
productid = prods.product_Id, //0
productname = prods.product_Name, //1
productimage = prods.product_Image, //2
productprice = prods.product_Price,//3
productdescr = prods.product_Description, //4
};
productbindingsource.DataSource = products;
productgridview.DataSource = productbindingsource;
productgridview.Columns[0].Visible = false;
productgridview.Columns[3].Visible = false;
productgridview.Columns[4].Visible = false;
}
Set the column's ImageLayout to the Stretch value to resolve this problem.
UPDATE: use the following code to change the ImageLayout property:
for(int i = 0; i < dataGridView1.Columns.Count; i ++)
if(dataGridView1.Columns[i] is DataGridViewImageColumn) {
((DataGridViewImageColumn)dataGridView1.Columns[i]).ImageLayout = DataGridViewImageCellLayout.Stretch;
break;
}
Set DataGridViewImageColumn.ImageLayout property to DataGridViewImageCellLayout.Zoom
If you set to "Stretch" your image will be inproportionally scaled to fit whole cell. And that is probably not what you want.
Set to zoom to have The graphic is uniformly enlarged until it fills the width or height of the containing cell.
By default the value is set to "Normal": The graphic is displayed centered using its native resolution.
first right click on grid go to properties of grid in that you will get column (collection) properties click on that. click on image column in that go in appearance-image layout-and choose stretch property you can also increase size of your image column.
its really helpful in that case .you have do not need for such type code.

Categories

Resources