The scenario is that of the employees table wherein there's an EmployeeId
and a ReportsTo field in the same table. The combobox is one in a datagrid
view that lets you select an employee from the employees table to fill in
the reportsto field, but since a person can't report to himself. I'm
wondering how to exclude the EmployeeId of the selected record from the
dropdown list of the combox. Ideally I think it would be to apply a filter
to the table that fills the combobox each time a new row is selected. Does
any one have any code snippets showing how to do that?
Any help would be appreciated.
Bob 2 1320
Hi,
"Bob" <bd*****@sgiims .com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. . The scenario is that of the employees table wherein there's an EmployeeId and a ReportsTo field in the same table. The combobox is one in a datagrid view that lets you select an employee from the employees table to fill in the reportsto field, but since a person can't report to himself. I'm wondering how to exclude the EmployeeId of the selected record from the dropdown list of the combox. Ideally I think it would be to apply a filter to the table that fills the combobox each time a new row is selected. Does any one have any code snippets showing how to do that? Any help would be appreciated.
Have a look at the DataGridView faq(A.18) at: http://forums.microsoft.com/MSDN/Sho...52467&SiteID=1
Applying it to your case, since you have circular reference you only need
one DataTable (and TableAdapter) eg. Employee. But you need 3
BindingSource's . One BindingSource is for the DataGridView, one for the
ReportsToComboB oxColumn and another only for the ComboBoxCell currently
being edited (and filtered). It's important that only the currently editing
ComboBoxCell has a filtered BindingSource, the others need the unfiltered
BindingSource so that they can correctly paint the lookup values.
What you need on the Form is the following:
- DataSet (eg. DataSet1) with a DataTable in it (eg. "Employee" )
- EmployeeBinding Source ( DataSource = DataSet1, DataMember="Emp loyee" )
- ReportsToBindin gSource ( DataSource = DataSet1, DataMember="Emp loyee" )
- ReportsToFilter edBindingSource ( DataSource = DataSet1,
DataMember="Emp loyee" )
- EmlpoyeeDataGri dView ( DataSource = EmployeeBinding Source )
- ReportsToDataGr idViewColumn
DataSource = ReportsToBindin gSource
DisplayMember=" EmployeeName"
ValueMember="Em ployeeId"
DataPropertyNam e="ReportsTo"
Then in code you need:
Private Sub EmployeesDataGr idView_CellBegi nEdit(...) Handles ...
If (
EmlpoyeesDataGr idView.Columns( e.ColumnIndex). DataPropertyNam e="ReportsTo" )
Then
Dim editingCombo As DataGridViewCom boBoxCell = _
EmployeesDataGr idView(e.Column Index, e.RowIndex)
ReportsToFilter edBindingSource .Filter = "EmployeeId <>" + _
EmployeesDataGr idView("Employe eId", e.RowIndex).Val ue.ToString()
editingCombo.Da taSource = ReportsToFilter edBindingSource
End If
End Sub
Private Sub EmployeesDataGr idView_CellEndE dit(...) Handles ...
If (
EmlpoyeesDataGr idView.Columns( e.ColumnIndex). DataPropertyNam e="ReportsTo" )
Then
Dim editingCombo As DataGridViewCom boBoxCell = _
EmployeesDataGr idView(e.Column Index, e.RowIndex)
editingCombo.Da taSource = ReportsToBindin gSource
End If
End Sub
HTH,
Greetings Bob
Thanks a lot Bart.
"Bart Mermuys" <bm************ *@hotmail.com> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl... Hi,
"Bob" <bd*****@sgiims .com> wrote in message news:%2******** *******@TK2MSFT NGP10.phx.gbl.. . The scenario is that of the employees table wherein there's an EmployeeId and a ReportsTo field in the same table. The combobox is one in a datagrid view that lets you select an employee from the employees table to fill in the reportsto field, but since a person can't report to himself. I'm wondering how to exclude the EmployeeId of the selected record from the dropdown list of the combox. Ideally I think it would be to apply a filter to the table that fills the combobox each time a new row is selected. Does any one have any code snippets showing how to do that? Any help would be appreciated.
Have a look at the DataGridView faq(A.18) at: http://forums.microsoft.com/MSDN/Sho...52467&SiteID=1
Applying it to your case, since you have circular reference you only need one DataTable (and TableAdapter) eg. Employee. But you need 3 BindingSource's . One BindingSource is for the DataGridView, one for the ReportsToComboB oxColumn and another only for the ComboBoxCell currently being edited (and filtered). It's important that only the currently editing ComboBoxCell has a filtered BindingSource, the others need the unfiltered BindingSource so that they can correctly paint the lookup values.
What you need on the Form is the following:
- DataSet (eg. DataSet1) with a DataTable in it (eg. "Employee" )
- EmployeeBinding Source ( DataSource = DataSet1, DataMember="Emp loyee" ) - ReportsToBindin gSource ( DataSource = DataSet1, DataMember="Emp loyee" ) - ReportsToFilter edBindingSource ( DataSource = DataSet1, DataMember="Emp loyee" )
- EmlpoyeeDataGri dView ( DataSource = EmployeeBinding Source ) - ReportsToDataGr idViewColumn DataSource = ReportsToBindin gSource DisplayMember=" EmployeeName" ValueMember="Em ployeeId" DataPropertyNam e="ReportsTo"
Then in code you need:
Private Sub EmployeesDataGr idView_CellBegi nEdit(...) Handles ...
If ( EmlpoyeesDataGr idView.Columns( e.ColumnIndex). DataPropertyNam e="ReportsTo" ) Then
Dim editingCombo As DataGridViewCom boBoxCell = _ EmployeesDataGr idView(e.Column Index, e.RowIndex)
ReportsToFilter edBindingSource .Filter = "EmployeeId <>" + _ EmployeesDataGr idView("Employe eId", e.RowIndex).Val ue.ToString()
editingCombo.Da taSource = ReportsToFilter edBindingSource End If End Sub
Private Sub EmployeesDataGr idView_CellEndE dit(...) Handles ...
If ( EmlpoyeesDataGr idView.Columns( e.ColumnIndex). DataPropertyNam e="ReportsTo" ) Then Dim editingCombo As DataGridViewCom boBoxCell = _ EmployeesDataGr idView(e.Column Index, e.RowIndex)
editingCombo.Da taSource = ReportsToBindin gSource End If End Sub
HTH, Greetings
Bob
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: VIJAY KUMAR |
last post by:
Hi all,
I have a problem with combobox. I have 2 comboxes cmbcategory and
cmbsubcategory.
I intialized cmbcategory with sum values from database on Form_Load.
when i select a vlue from the cmbcategory, i will get sub categories in
cmbsubcategory.
on Form load when ever cmbcategory is initializing its automatically
|
by: raj |
last post by:
Please Help with the combox DisplayValue property
private void cboClient_SelectionChangeCommitted(object sender,
System.EventArgs e)
{
String strSQL;
strSQL = "SELECT F.FollowUpPerson FROM tblFollowUpPerson F INNER JOIN
tblFollowUpPersonClient C ON F.FollowUpPersonID = C.FollowUpPersonID WHERE
C.ClientKey = '" + this.cboClient.SelectedValue + "' ";
ds = mg.GetDataSet(strSQL,"userList"); //Def is described at the end
|
by: Charles A. Lackman |
last post by:
Hello, I have a combox that I am trying to get to work in the following
fashion.
As you type in the combox that the item that matches what you are type is
selected.
as you type a last name:
Leyman
|
by: Alpha |
last post by:
This is a Window based application. How do I get my combox listing to
display in sorted order by DataMember? I inserted a blank row to the dataset
table which is the datasrouce for the comboBox with valuemember wet to -1.
This is showing up at the bottom of the list. I want it to show at the top
of the listing. How can I do that?
Thanks, Alpha
|
by: yevvi |
last post by:
Hi,
We have a product with bunch of dlls which are now built with Visual
Studio 2003. We want to switch the build to use VS2005. I have read
that in VS2005 runtime libraries come as side-by-side assemblies and
that application has to have a manifest binding it to those assemblies.
My question is, can previously built apps use my new dlls build with
vs2005? It would be really important to make it work, because
otherwise we would...
| |
by: =?Utf-8?B?TmFkYXYgUG9wcGxld2VsbA==?= |
last post by:
Hi everybody,
I've got two questions about using the EnableSession property with an
ASP.NET WebService:
First Question:
I'm trying to create a web service with EnableSession=true.
I can't get it to work with VS2005 ( It works with vs2003!).
Here is my testcase:
|
by: neo1ra |
last post by:
Hi,
I'm doing a search combox to pop up and specific record. Everything is working fine until I make a change to the record that I'm working on and try to move to other record. A error message appear that said " Update or CancelUpdate without Addnew or Edit". I think that I need to add a message box that ask you if you want to save the record or not, but I don't know how to do it because I'm new in Access. Here is the code that I'm using...
|
by: haringmunti |
last post by:
hi,
im new to vb.net and i think it is very interesting. im taking a course on it right now and sadly, the one giving the lecture is not doing a good job.
anyway, my question is how do i make a calendar using the combox box. i looked in one site and it shows you how to use "for" and "next" but that is only for integers. when it runs, i want people to select the month from January to December.
Your help will be greatly appreciated.
|
by: dewgan |
last post by:
I have a form with a combox box where the list is populated via a linked table. This works fine. I have a text box that is filled with the name selected in the combox box. That name is then added to another table. That works fine. My problem is this, I want to keep the second table from being populated with the same name. So, for exampe, if I select the name John Smith in the Combo box but John Smith already exist in the second table, I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |