473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

User Control -> disappear when form.Click

Hi,
i've got an inherited usercontrol with added DataGridView. I plant my
control on form and I want to hide datagridview when user click on
that form.

I've tried to use LostFocus and Leave. It works great, when focus is
set to other control on form, but not fired on form.Click.

Is there any solution?
Best regards,
Mrozu
Sep 22 '08 #1
4 1805

I may be misunderstanding what you are trying to do. Does this example
represent something like what you are trying to do?

Here's my example user control:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class UserControl1 : UserControl
{
bool _IsVisible = true;
public delegate void OnClickHandler(object sender, System.EventArgs e);
public event OnClickHandler ClickHandler;
public UserControl1()
{
InitializeComponent();
}
public bool IsButtonVisible
{
get { return _IsVisible; }
set
{
_IsVisible = value;
this.button1.Visible = _IsVisible;
}
}
private void panel1_Click(object sender, EventArgs e)
{
if (ClickHandler != null)
ClickHandler(this, e);
}
}
}
Here's my app:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_Click(object sender, EventArgs e)
{
this.userControl11.IsButtonVisible = false;
}
private void userControl11_Click(object sender, EventArgs e)
{
this.userControl11.IsButtonVisible = true;
}
}
}

You can also bury the visibility behavior in the user conrtol if you
want it invisible to the developer.
--
breitak67
Sep 23 '08 #2
Hi, thanks for quick answer.
i think that you don't understand me at all.
my control inherits LinkLabel. Then, i add to my control DatagridView,
and on Me.Click (click on label text) datagridview is appearing under
LinkLabel.
Then, when I click on row, it's getting data from column and hiding
datagrid. But I want to hide it also on form.click (just like for
example combobox is)

any suggestion now?:)

Mrozu
Sep 23 '08 #3

Ah, now I understand. I think a small tweak to what I posted before
does exactly what you want, except with a composite control rather than
a subclass of the linklabel control. I'll give the subclass a try and
post back. This is the composite control version (not pretty to look
at, but basically functional):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class UserControl1 : UserControl
{
bool _IsVisible = false;
public delegate void OnClickHandler(object sender, System.EventArgs e);
public event OnClickHandler ClickHandler;
public UserControl1()
{
InitializeComponent();
_IsVisible = false;
this.dataGridView1.Visible = _IsVisible;
DataTable dt = new DataTable();
dt.Columns.Add(\"ID\", System.Type.GetType(\"System.Int32\"));
dt.Columns.Add(\"Desc\", System.Type.GetType(\"System.String\"));

DataRow dr = dt.NewRow();
dr[\"ID\"] = 1; dr[\"Desc\"] = \"Row 1\";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[\"ID\"] = 2; dr[\"Desc\"] = \"Row 2\";
dt.Rows.Add(dr);
this.dataGridView1.DataSource = dt;

}
public bool IsGridVisible
{
get { return _IsVisible; }
set
{
_IsVisible = value;
this.dataGridView1.Visible = _IsVisible;
}
}
private void panel1_Click(object sender, EventArgs e)
{
if (ClickHandler != null)
ClickHandler(this, e);
}
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
this.IsGridVisible = true;
}
private void dataGridView1_CellMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{
this.textBox1.Text = dataGridView1[e.ColumnIndex,
e.RowIndex].Value.ToString();
this.IsGridVisible = false;
}
private void UserControl1_Click(object sender, EventArgs e)
{
this.IsGridVisible = false;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Click(object sender, EventArgs e)
{
this.userControl11.IsGridVisible = false;
}
private void userControl11_Click(object sender, EventArgs e)
{
this.userControl11.IsGridVisible = true;
}
}
}
--
breitak67
Sep 23 '08 #4

I think this does what you want. It needs some cosmetic work, but
functionally behaves like a combobox:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SubclassLinkLabelTest
{
public partial class Form1 : Form
{
private ExtraSpecialLinkLabel MyExtraSpecialLinkLabel = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyExtraSpecialLinkLabel = new ExtraSpecialLinkLabel();
this.Controls.Add(MyExtraSpecialLinkLabel);
MyExtraSpecialLinkLabel.Top = 20;
MyExtraSpecialLinkLabel.Left = 10;
MyExtraSpecialLinkLabel.Width = 300;
MyExtraSpecialLinkLabel.Height = 200;
MyExtraSpecialLinkLabel.Text = \"Click Me\";
MyExtraSpecialLinkLabel.Visible = true;
}
private void Form1_Click(object sender, EventArgs e)
{
MyExtraSpecialLinkLabel.IsGridVisible = false;
}
}
public class ExtraSpecialLinkLabel : LinkLabel
{
private DataGridView MyGrid = null;
private bool _IsGridVisible = false;
public ExtraSpecialLinkLabel()
{
_IsGridVisible = false;
this.BackColor = Color.LightGray;
MyGrid = new DataGridView();
DataTable dt = new DataTable();
dt.Columns.Add(\"Desc\", System.Type.GetType(\"System.String\"));
DataRow dr = dt.NewRow();
dr[\"Desc\"] = \"Row 1\";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[\"Desc\"] = \"Row 2\";
dt.Rows.Add(dr);
MyGrid.DataSource = dt;
this.Controls.Add(MyGrid);
MyGrid.Top = 20;
MyGrid.Left = 10;
MyGrid.Visible = _IsGridVisible;
MyGrid.CellClick += new DataGridViewCellEventHandler(MyGrid_CellClick);
}
void MyGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.Text = MyGrid[e.ColumnIndex, e.RowIndex].Value.ToString();
MyGrid.Visible = false;
}
protected override void OnClick(EventArgs e)
{
this.IsGridVisible = false;
}
protected override void OnLinkClicked(LinkLabelLinkClickedEventArgs e)
{
this.IsGridVisible = true;
}
public bool IsGridVisible
{
get { return _IsGridVisible; }
set
{
_IsGridVisible = value;
MyGrid.Visible = _IsGridVisible;
}
}
}
}
--
breitak67
Sep 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andrea Williams | last post by:
I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do is be able to set a Label.Text in the user control...
1
by: moondaddy | last post by:
I need to replace a user control on a page with a different user control. The challenge I'm faced with is that this call is being made from the user control being replaced. Normally I replace...
0
by: Jeff Schaefer | last post by:
What I want to know is this: Is it possible to programmatically manipulate a custom property of a user control for which <%@ OutputCache ... > has been included? If so, then how? My brief code is...
6
by: Jim Heavey | last post by:
Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a...
4
by: DotNetJunkies User | last post by:
I have created a User Control (a Pareto Chart) using C#. It works great in .Net Windows Apps, but I also need to use it in a Web Application (to view in IE). Everything I read on this seems to be...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
1
by: Stanley Cheung | last post by:
Dear all, how can I pass a parameter to dynamic user control? As I know we can pass parameter into traditional user control. e.g: add pageid into user control and write a property from user...
0
by: CBeers | last post by:
I currently have a project in production running under ASP.NET 1.1. The project contains a page that loads a User Control dynamically in the Page_Load event and then adds the User Control to a...
1
by: zeya_bakhtyar | last post by:
Here is the page architecture: Page loads multiple user controls (including nested user controls) dynamically based on parameters provided into place holders. Note: The page only has the logic to...
3
by: Fred Chateau | last post by:
I am trying to access a user control class, for a user control that is loaded dynamically, from the containing page. I have been able to access Web controls in the user control, but so far I have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.