 |
|
 |
please help me i kind of new with vb.net and Im using vb.net 2003 i cant quite figure out the code that you posted can you please upload a sample program so that i can understand it much easier thanks...
|
|
|
|
 |
|
 |
thanks for sharing this control - It works great for me.
|
|
|
|
 |
|
 |
I have got problem . link is ok ,but style is not. have a cell white that I don't want display . Pls let me know that why ? . Thanks alot
http://ruthamcau.com/pic/help.jpg[^]
Lionvn
|
|
|
|
 |
|
 |
When does that cell appear?
Did you click somewhere on the grid or what else?
|
|
|
|
 |
|
 |
Hi Lino Barreca,
when first load , Cell auto appear .
as that you write , I click on the grid ,so it disappear .
for the reason , I don't know .
Thanks & regards ,
fd
|
|
|
|
 |
|
 |
I was happy to find this, but ran into a serious block when I realized that it doesn't work for multiple columns in the same table. The MouseMove event handler is bound to the table, not to an individual column. After a bit more searching I now have the following simpler code that mostly accomplishes the same thing (I haven't implemented every option yet) by creating a LinkLabel for every cell, rather than having a single control that is hidden when leaving a cell. This is based on another Code Project article by Nidhi Shrivastava (http://www.codeproject.com/vb/net/Datagrid_ColumnStyles.asp), with a bit of your code thrown in: using System; using System.Windows.Forms; using System.Data; using System.Collections; namespace CustomControls { /// <summary> /// Summary description for LinkLabelColumnStyle. /// </summary> public class DataGridLinkLabelColumn : DataGridColumnStyle { private ArrayList _linkList = new ArrayList(); public event LinkLabelLinkClickedEventHandler LinkClicked; public DataGridLinkLabelColumn() { } protected override void Abort(int rowNum) { // Do nothing...this is not an editable column style } protected override bool Commit(CurrencyManager dataSource, int rowNum) { // Do nothing...this is not an editable column style return false; } protected override void Edit(CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) { // Do nothing...this is not an editable column style } protected override int GetMinimumHeight() { return 0; } protected override int GetPreferredHeight(System.Drawing.Graphics g, object value) { return GetPreferredSize(g, value).Height; } protected override System.Drawing.Size GetPreferredSize(System.Drawing.Graphics g, object value) { LinkLabel temp = new LinkLabel(); temp.Text = (value == null ? string.Empty : value.ToString()); return new System.Drawing.Size(temp.PreferredWidth, temp.PreferredHeight); } protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum) { Paint(g, bounds, source, rowNum, false); } protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) { Paint(g, bounds, source, rowNum, null, null, alignToRight); } protected void AllocateControls(int count) { _linkList.Clear(); for (int i = 0; i < count; ++i) { LinkLabel l = new LinkLabel(); l.LinkBehavior = LinkBehavior.HoverUnderline; l.Visible = false; l.Links.Add(0, 0, null); l.Parent = DataGridTableStyle.DataGrid; l.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkLabelClicked); _linkList.Add(l); } } private LinkLabel GetLinkLabel(int rowNum) { return (LinkLabel) _linkList[rowNum]; } protected override void Paint( System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) { // Here's the real work. Create a linklabel for every row // First, if the list doesn't have enough values, grow the list if (_linkList.Count <= source.List.Count) { AllocateControls(source.List.Count); } // Now retrieve the specific control for this cell LinkLabel rowLink = (LinkLabel) _linkList[rowNum]; object cellValue = GetColumnValueAtRow(source, rowNum); string linkText = cellValue == null ? string.Empty : cellValue.ToString(); rowLink.Text = linkText; LinkLabel.Link link = rowLink.Links[0]; link.LinkData = source.List[rowNum]; link.Length = linkText.Length; rowLink.Bounds = bounds; rowLink.Visible = true; } private void LinkLabelClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (LinkClicked != null) { LinkClicked(sender, e); } } } }
|
|
|
|
 |
|
 |
Well.. It can be adapted to work for multiple columns because the mouse can only be on one cell only at a time so you don't need more than ONE linklabel
Moreover..Each columnstyle creates a Linklabel to place (there's a linklabel for each column) so each column can handle its linklabel.
I already tried with creating a linklabel for each cell (it's more simple to handle because each CELL has a linklabel with its properties) but I found some problems (that actually I don't remember, unfortunately) that made me change the design this way.
Thanks for your interest, I'm glad I was useful to help you design a new control that meets your needs And please, let me know if you find some problems with this approach.
Best regards
Lino.
|
|
|
|
 |
|
 |
Your code is really simple to understand.
But there is a big bug in it. It does not add the LinkLabel column as the part of the grid. I mean if you write datagrid_OnMouseDown event, this event doesn't catch the clicks when on any of the items in this column, although onMouseDown event is working perfectly for other columns in the grid.
Please reply as soon as possible.
thanks.
|
|
|
|
 |
|
 |
Sorry forgot to mention that the above comments are meant for Jay M Miller' code.
|
|
|
|
 |
|
 |
Do you have a sample project that actually uses your linklabel datagrid column file that you provided for download? It would help me to understand how to use this control more.
Thank you very much.
|
|
|
|
 |
|
 |
How can I get a reference to the clicked cell item in the DataGrid?
I tried using the line commented out in your example:
DirectCast(e.Link.LinkData, DataRowView)
but this caused a SystemInvalidCastException to be thrown. It looks like I can only get a reference to the e.Link.LinkData, and not to the row itself. Any ideas?
Thanks
|
|
|
|
 |
|
 |
well.. I actually use this:
Private Sub SetGrid()
[...]
grdListaStileColEquivalenti.MappingName = "Equivalenti"
grdListaStileColEquivalenti.HeaderText = "Eqv."
grdListaStileColEquivalenti.Alignment = HorizontalAlignment.Center
grdListaStileColEquivalenti.NullText = ""
grdListaStileColEquivalenti.Width = 40
AddHandler grdListaStileColEquivalenti.LinkClicked, AddressOf LinkClicked
[...]
grdLista.DataSource = dtbRecords
[...]
End Sub
Private Sub LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)
st_CodiceEquivalenza = CStr(DirectCast(e.Link.LinkData, DataRowView).Row.Item("CodEqvPro"))
End Sub
I can't figure out why you obtain an InvalidCastException.
e.Link.LinkData contains the object returned by the CurrencyManager that should be a DataRowView.
What kind of object do you obtain?
How do you fill your grid?
What does the CurrencyManager returns?
|
|
|
|
 |
|
 |
Thanks for the quick reply. I managed to sort out the e.Link.LinkData problem, it was my mistake! I am working in VB.NET and using version 1.1 of the framework. So there was some errors in my code conversion.
If you can help I am still having a few troubles:
There is no ctrl.MinimumSize.Height attribute. I think this may be causing my text links to move around when the cursor rolls over them.
For the ctrl_Clicked event, I have had to use a VB RaiseEvent statement for the code to compile, but unfotunatley I can't find a way to test the LinkClicked event status for null. I think this may be causing an exception when the DataGrid returns no rows. Is there a way round this? Sorry if you are not familiar with VB!
Also I have noticed that when the WinForm is initialised a white block appears at the top left of the DataGrid for a few seconds. Any idea what might cause this bug?
Many very much thanks for your help.
|
|
|
|
 |
|
 |
The LinkLabel Control is written in C# and the example to use it is in VB. A bit strange, but yeah why not.
It doesn't compile in framework 1.1
Control.MinimumSize Property does not exist.
Also the hittest doesn't function with a location but with a point.
The only real problem I had was the fact that you get a System.ArgumentNullException if you make the TableGridStyle before setting the datasource.
Bug can be find in the method SetDataGridInColumn. Following line is responsible
value.BindingContext[value.DataSource, value.DataMember].PositionChanged += new EventHandler(DataGridBinding_PositionChanged); // DataSource is NULL, so exception when datasource is not set.
But anyway I was very very happy with this control, thank you.
Kris
|
|
|
|
 |
|
 |
>It doesn't compile in framework 1.1
Yes. I wrote it in .NET 2.0 (as you can read from the top-right description) because I actually use it on a .NET 2.0 project but it's easy to adapt it to .NET 1.1 (there're some very minor changes you have to do and, as I can read, you already did)
>The only real problem I had was the fact that you get a System.ArgumentNullException if you make the TableGridStyle before setting the datasource.
Bug can be find in the method SetDataGridInColumn.
Well..this is not a bug..
I forgot to say that you MUST create the datasource (even if empty, but NOT NULL) before creating the DatagridTableStyle.
Maybe I should add a (if ==NULL) throw new ArgumentNullException("datasource must not be null") (but I didn't that because the ArgumentNullException it is already thrown by the statement you said)
The reason is simple:
You could skip the execution of the instruction if the datasource is null but doing this will make you miss the PositionChanged event of the datasource itself (useful if you change the position programmatically) or bind to that event later..
I/You should add some method that gets invoked when you actually do the NEW on the datasource (the object is created) and in that method I should bind to the PositionChanged event.
Unfortunately I didn't find a simple way to do this (an event on the creation of the object?) let me know if you do.
I'll modify the code accordingly (giving you credits, obviously)
You could create a public method in the tablestyle and call it manually after the new statement but personally I don't like this apporach.
Have a nice day
|
|
|
|
 |
|
 |
I've searched this for a lot!
Thank you.
|
|
|
|
 |