Solved

Can I know the top and width of the current cell On datagridview

Posted on 2008-06-16
16
313 Views
Last Modified: 2012-06-27
Can I know the top and width of the current cell On datagridview  or any cell
0
Comment
Question by:Ahmadal_najjar2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21792034
You can look in the row or column width, but can you explain better what you want ?
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21795209
I really have an idea in my mind when the user want to make a bill by using datagridview. there are columns such as (ProductCode , ProductDesc) . the user may not saving the product code in his mind so I will give him option to type some text of the product description and the send a command to sql server database with like %% then I put the result which may contain more than one item into a listbox to select from . I want to put this listbox in the same place of productdesc column until he select the item then I make it unvisible.

If you have another idea.

Ahmad
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21795260
That is more hard (not impossible) to achive but ...

I would add a button on the row and when he clicks, it just open a modal form with the search option. Then after the user select/accept the product code, it closes the form and add that code to the current row of the datagridview.

Another option is to insert a combobox with all the options (but I like more the first one)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ahmadal_najjar2003
ID: 21796016
I don't think it is imposible. I did it but I need the listbox to follow the currentrow to bo opened as proffecien way.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21796898
>> I don't think it is imposible

I didn't say that! You want the listbox near to the cell, right ?
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21799461
I don't think it is imposible. I did it but I need the listbox to follow the currentrow to bo opened as proffecien way.
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21799470
First sorry for (imposible) because you said (not imposible) . Second sorry for repeate the comment , some error with my internet.

Thats right i need it neer the cell ?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21801370
>> First sorry for (imposible) because you said (not imposible) . Second sorry for repeate the comment , some error with my internet.

No problem :)

You can do something like this to display the listbox near to the row you have selected (you can use cell enter event or other). You then can show/hide as you like.
        Dim recRow As New Drawing.Rectangle
        Dim recCol As New Drawing.Rectangle
 
        With Me.DataGridView1
            recRow = .GetRowDisplayRectangle(.CurrentCell.RowIndex, False)
            recCol = .GetColumnDisplayRectangle(.CurrentCell.ColumnIndex, False)
            Me.ListBox1.Left = recCol.X + 10
            Me.ListBox1.Top = recRow.Y + .CurrentRow.Height + 10
        End With

Open in new window

0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21809726
I tried it but not success will with me.
But What I think as I Want listbox to be within the ProdectDesc only. and at design time I put it on product desc column. Then each time at runtime I just change the Top of it as follow
ListBox1.Top = ListBoxOriginalTop + .current.Height * RowIndex   ' as rowindex is fixed for all rows

And it works fine.

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21810532
>> ListBox1.Top = ListBoxOriginalTop + .current.Height * RowIndex   ' as rowindex is fixed for all rows

But that way you cannot change the size of the rows. The method that I have showed you works fine for shure - I have tested (of course).

You just need the check what column is select:
If Me.DataGridView1.CurrentCell.ColumnIndex = 2 Then
  ' show the listbox
End If

What else problems did you found ?
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21812428
ok ,
My listbox top  as design time is = 160

after
   Me.ListBox1.Top = recRow.Y + .CurrentRow.Height + 10
is 35+22+10 = 67

so now list box out of datagridview
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21812450
Have you used the cellenter event for the code I have showed you ?

I will upload a simple sample.
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21812504
Yes Now I tried it with CellEnter , but the problem still exists with Top.
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21812666
Opppsss! I'm really sorry but I have posted the wrong code!

That was the first test I have done.  Try this one now and sorry once again:
     Private Sub DataGridView1_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        Dim recRow As New Drawing.Rectangle
        Dim recCol As New Drawing.Rectangle
 
        With Me.DataGridView1
            recRow = .GetRowDisplayRectangle(.CurrentCell.RowIndex, False)
            recCol = .GetColumnDisplayRectangle(.CurrentCell.ColumnIndex, False)
            Me.ListBox1.Left = recCol.X + .Left + 10
            Me.ListBox1.Top = recRow.Y + .Top + 10
        End With
    End Sub

Open in new window

0
 

Author Closing Comment

by:Ahmadal_najjar2003
ID: 31467494
Thank You.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21813108
Glad I could help!

jpaulino
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 92
Problem to With line 4 87
VB6 calling COM DLL written in Visual Studio 2003 6 58
2 Global Vars, 1 List Box 4 34
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question