|
How can I get the position of a certain cell of a datagridview. To be specific I don't want the mouse coordinates. Suppose I have a datagridview with Name (ReadOnly), ID and TransDate columns and I want to popup a tiny lookup form when the mouse is clicked or Enter button is pressed when the focus is upon the Name column. The lookup form should openup exactly upon the Name column of the selected row. Thanks.
|
|
|
|
|
You can use CellBeginEdit event for this. Check the current column index and if it is name, show the look up form. You can set the location for the form according to the current cell.
BTW, what EditMode have you set for the DataGridView?
|
|
|
|
|
Here's a solution I came up to.
I am opening a dialog form above the datagridview form. In Form1 I have a datagridview containing few columns among which is 'TransDate' column having index 8. When I click on it, frmDate opens up exactly on it. My revised code follows:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridview1.CellClick
If DataGridview1.CurrentCell.OwningColumn.Name = "TransDate" Then
Dim objPoint As Point
'Getting the exact location of the cell with respect to Form1.
'Note- Me.Location is added here alongwith DataGridView1.Location and
'DataGridView1.GetDisplayRectangle().Location.
'This is done because the form frmDate we are calling is external to Form1 and if we don't add
'Me.Location
'here, frmDate won't open exactly at the desired point if we move or resize Form1. Instead of
'frmDate if we use any control inside Form1 to place over 'TransDate' column then remove
'Me.Location here and the next two lines.
objPoint = (Me.Location + DataGridview1.Location + DataGridview1.GetCellDisplayRectangle(8,
DataGridview1.CurrentCellAddress.Y, True).Location)
'Setting the exact location where frmDate will be opened. The last digits may vary according to
'your requirement.
objPoint.X = objPoint.X - 158
objPoint.Y = objPoint.Y + 28
objFrmDate = New frmDate()
objFrmDate.Location = objPoint
objFrmDate.ShowDialog(Me)
objFrmDate = Nothing
End If
End Sub
Regards.
|
|
|
|
|
Hi,
How about enhance it, and make it general to benefit from it more, like this.
this code is in C#.
-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace MyNamespace
{
public class ControlUtilityClass
{
public static Rectangle Get_DataGridCellLocationAndSize(DataGridViewCell cell)
{
Rectangle result;
Rectangle rec = cell.DataGridView.GetCellDisplayRectangle(cell.ColumnIndex,
cell.RowIndex, false);
Rectangle rec1 = cell.DataGridView.RectangleToScreen(rec);
result = cell.DataGridView.FindForm().RectangleToClient(rec1);
return result;
}
}
}
modified on Wednesday, June 30, 2010 2:09 AM
|
|
|
|
|
DESKTOP APPLICATION.
Hi, below is the problem briefed:
In my home form I have a splitcontainer and few buttons. When the buttons are clicked respective forms are opened in the splitcontainer. The splitcontainer is anchored- top, left, right, bottom so that when the home form is resized the splitcontainer resizes itself automatically. The controls within the other forms are also anchored properly to resize themselves accordingly. But the problem is when i open a form in the splitcontainer, even if I resize the home form, the controls in the form within the splitcontainer aren't resizing. The reason is when the home form is resized the splitcontainer is resizing itself accordingly but the form inside the splitcontainer isn't (as forms don't have anchor or dock properties so I couldn't set them). As a result though the controls in the sub form are anchored to resize themselves yet they aren't. How to solve it.
In short I want the form in the splitcontainer and all the controls in it to resize automatically when the home form/splitcontainer is resized. Regards.
|
|
|
|
|
AFAIK a Form is a Control, and hence has an Anchor property. It will only work when its TopLevel property is set false.
If that does not work, and assuming the Form is resizable, I would add a handler to the SplitContainer's panel, and write the code that resizes the Form it is holding. The Controls inside the Form will then do whatever their designer decided they should do.
|
|
|
|
|
Never mind! I missed a small property. When you call the subform in the splitcontainer of the main form just set the property Dock to Fill.
dim objFrmSubForm as New frmSubForm()
objFrmSubForm.Dock=DockStyle.Fill
objFrmSubForm.Show()
objFrmSubForm=Nothing
Regards.
|
|
|
|
|
User user = FillObject(o);
opContext.AddToUsers(user);
opContext.SaveChanges();
opContext.AcceptAllChanges();
Fill Object is my private method which returns an user object.
Savechanges does not save changes to the database at the same time
does not throw error.
I am using sql express 2008 express edition and visual studio 2010
release candidate. Let me know if some body has the same problem.
Is there any setting on sqlserver express edition which i have to turn on.
The piece of code seems to work when i use sql server 2005 on a different
machine
Any help is greatly appreciated
|
|
|
|
|
EF is really agnostic when it comes to versions, if it works with SQL Server 2005 it will work with SQL 2008, Express or otherwise, so I don't buy that it works with one and not with the other. Try debugging through your code, there is obviously something wrong but without seeing whats in FillObject we can't comment.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Nothing is there in Fill object
private User FillObject(UserInfoDO o)
{
User user = new User();
user.UserId = o.UserId;
user.LastName = o.LastName;
user.FirstName = o.FirstName;
user.Password = o.Password;
user.Lockout = o.Lockout;
user.Active = o.Active;
user.Email1 = o.Email1;
user.Email2 = o.Email2;
user.HomePhone = o.HomePhone;
user.MobilePhone = o.MobilePhone;
user.WorkPhone = o.WorkPhone;
user.CreateTime = o.CreateTime;
return user;
}
It is just transefring data from one place to another
|
|
|
|
|
I'll assume UserId is the primary key for the entity. In which case AddToUsers will not always work as I think you are expecting it to. If a user already exists then you want to update it not add a new one.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I agree with you. But for testing purposes iam sending a new userid every time.
and it still does not work and more importantly does not throw an error
|
|
|
|
|
A wild guess: could it be you have two databases, one you are looking at, and one your app is working with (and which gets copied by your build process)?
|
|
|
|
|
I am getting this message when I attempt to run a report in my WinForms app:
The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception
I have spent the last week Googling and researching this. I have tried many different things, and I'm still getting it. It doesn't occur on my development machine, only on my test box.
I know there's not much here to go on, but I'm really stuck and I have to deliver this soon.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Among the things you tried, did you do a reinstall?
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Reinstall what?
I have reinstalled my app multiple times. Reinstalled CR multiple times.
Been there, done that.
Everything makes sense in someone's mind
|
|
|
|
|
i ve developed an audio mixer working for wave files.i need to save the recorded wave file in compressed format.so need a c# code for that.also code for taking mic input........
|
|
|
|
|
Are you expecting someone to write code for you?
I'll do it, but I charge $100/hour. If you're interested, email me. Otherwise, take a look here:
http://lmgtfy.com/?q=C%23+Audio+Mixer[^]
Everything makes sense in someone's mind
|
|
|
|
|
Man, you're expensive.
Regards,
Rob Philpott.
|
|
|
|
|
You get what you pay for.
Everything makes sense in someone's mind
|
|
|
|
|
I'll take the offshore approach and do it for $40/hour
Of course it will be late, of poor quality and need to be rewritten
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yup. You get what you pay for.
Everything makes sense in someone's mind
|
|
|
|
|
how about 10$/hr... i will keep billing u... and u can keep waiting
|
|
|
|
|
Afternoon,
Subject just says it all really. I need to communicate with a mobile device over bluetooth from a PC. I've been reading stuff that suggests a virtual COM port is the way to go, but I'm hoping there's a better way.
Anyone had any experience of this stuff?
Regards,
Rob Philpott.
|
|
|
|
|