Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# code to show datagridview cell value on Balloon Tooltip

Posted on 2009-05-11
29
Medium Priority
?
5,991 Views
Last Modified: 2012-05-06
Please provide C# sample code to show datagrid view cell value on Balloon Tooltip
0
Comment
Question by:Amitava_Mukherjee
[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
  • 18
  • 10
29 Comments
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361248
You could probably use the CellMouseEnter event of the datagridview  and then use the eventargs of the event to get your value using e.ColumnIndex and e.RowIndex.
Once you get the value you could display that in a tooltip set as balloon style..
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361360
Please provide C# sample code
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361372
Here is VB code to get the info you need...I have never tried this so there might need to be some tweaks... I will try to convert as well..
 

    Private Sub DataGridView1_CellMouseEnter( _
                        ByVal sender As Object, _
                        ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
                        Handles DataGridView1.CellMouseEnter
 
        If e.RowIndex >= 0 And e.ColumnIndex >= 0 Then
 
            DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
            Dim s As String = DataGridView1.CurrentCell.Value
            MsgBox(s)
 
        End If
 
 
 
    End Sub

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:rgn2121
ID: 24361383
Paste the code below into the event I mentioned...
    if (e.RowIndex >= 0 & e.ColumnIndex >= 0) { 
        
        DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex); 
        string s = DataGridView1.CurrentCell.Value; 
            
        Interaction.MsgBox(s); 
    } 

Open in new window

0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361403
Like I said...I didn't really do an error checking or validate much...good luck

    if (e.RowIndex >= 0 & e.ColumnIndex >= 0) { 
        
        DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex); 
            
        DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).ToolTipText = DataGridView1.CurrentCell.Value; 
    } 

Open in new window

0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361407
Last time...this would be better..
    if (e.RowIndex >= 0 & e.ColumnIndex >= 0) { 
        
        DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).ToolTipText = DataGridView1.CurrentCell.Value; 
    } 

Open in new window

0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361415
never mind that...I posted before I read the code...Go with the the second to last one.
 
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361436
Oh...and althought I am not certain, I think if you want a balloon tooltip then you need to add the tooltip control.  I am not sure you can change the type of tooltip built in to the grid...
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361527
The value show in Message Box [MessageBox.Show(s)], But not working in Balloon Tooltip, the default Tooltip show the value.
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361600
Shows in normal Tooltip, but not in Balloon Tooltip.
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361654

    if (e.RowIndex >= 0 & e.ColumnIndex >= 0) { 
        
        DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex); 
        this.mainToolTip.SetToolTip(DataGridView1, DataGridView1.CurrentCell.Value); 
            
        this.mainToolTip.Active = true; 
    } 

Open in new window

0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361664
I dropped a tooltip control on the form and then change the IsBalloon property to design view as well as some of the display delays.
Using the code above it worked as expected...
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361840
Please send your sample project as an attachment
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361860
I didn't create a sample project...
0
 
LVL 12

Accepted Solution

by:
rgn2121 earned 2000 total points
ID: 24361883
If I did, I could do it by following these steps:
1.   Create a windows application project
2.  drop a datagridview and a tooltip control on the form.
3.  add code to fill the datagridview with data on Form_Load
4.  Add the code I provided for the CellMouseEnter event of the DataGridView
5.  In design view, change the ShowCellTooltips property of the DataGridView to False
6.  In desgin View, change the IsBalloon property of the ToolTip control to True.
7.  In desgin View, change the design Name property of the ToolTip control to mainToolTip
run the app...
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361888
I am trying as per your instructions, but it is not working, please send a sample project containing the solution that you provided.
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361943
are you getting errors or what...
 
0
 
LVL 12

Assisted Solution

by:rgn2121
rgn2121 earned 2000 total points
ID: 24361947
I don't use C#, but it looks like the converter I used had a few errors...If you didn't correct them then it wouldn't build.  Here is the revised code for the CellMouseEnter event...
 

        private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 & e.ColumnIndex >= 0)
            {
 
                dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                this.mainToolTip.SetToolTip(dataGridView1, dataGridView1.CurrentCell.Value.ToString());
 
                this.mainToolTip.Active = true;
            } 
 
        }

Open in new window

0
 

Author Comment

by:Amitava_Mukherjee
ID: 24361956
The call value Shows in normal Tooltip as well as Message Box, But NOT in Balloon Tooltip
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24361989
First off, like I stated above, the default tooltip with the DataGridView should be set to FALSE.  If I don't do that on mine...it doesn't work.
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24362016
I followed the same steps as above in an app I have, which already had a datasource for the grid, which I cannot upload.

sample.png
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24362045
How you set the default tooltip value of DataGridView is FALSE.
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24362059
Thankx..
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24362092
Click on the DataGridView Control  in Design View.  Then in the Properties Window find the property called ShowCellToolTips.  Change it to False....
sample.png
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24362204
Is it working now?
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24362333
Yes
0
 

Author Comment

by:Amitava_Mukherjee
ID: 24362393
It is working
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24362455
Instead of selecting almost every post I made as an answer, I think it would be more beneficial to those that come across this question if we split the points between ID: 24361883 (Tells how to setup the project) and ID: 24361947 (The final valid code posted.)
rgn
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

718 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