|
|
Hi guys,
Been struggling with this and thought I had gotten it right when I realised my way affected the functionality of the databindingsource.
I have 2 databound comboboxes. The first contains a list of industry categories and the second contains the companies in those industries. I need the second combobox to only show companies that fall in the industry category selected in the first combobox. This needs to update whenever the records are navigated or the selection in the first combobox changes.
The way I did it (tried using companybindingsource.filter and refilling the company table on every selection) causes "haschanges" on the dataset and also screws up my "add new record".
If anybody could help me or point me to an example I would be grateful.
Thank you
Ed
|
|
|
|
|
Just handle the selected index changed of the first combo and then run SQL to select a new data source for the second. Sounds to me like you're using the built in SQL data source rubbish, throw that in the bin, write real code and you'll find you'll regain complete control over wat your program does.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hi,
however Christian Graus already answer this question in therotically. if you have any problem in apply this thing practicaly then consider following
first of all use following statement in declaration section
Private ComboBox1LoadTime As Boolean<br />
Dim ds, ds1 As New DataSet
<br />
now fill the combo box as following at load event of form <br />
<br />
Dim str As String<br />
<br />
Dim mdins As New mdGlobal 'here mdglobal is <br />
str = "select areaname,areaid from areainfo"<br />
ds = New DataSet<br />
ComboBox1LoadTime = True<br />
ds = mdins.GetResultFromQuery(str)<br />
'in above statement i use class mdglobal which is created by me. and GetResultFromQuery return dataset<br />
<br />
ComboBox1.DataSource = ds.Tables(0)<br />
ComboBox1.DisplayMember = "AreaName"<br />
ComboBox1.ValueMember = "Areaid"<br />
ComboBox1LoadTime = False<br />
ComboBox1.SelectedIndex = -1
Now on selected index change event of combobox1 use following code
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
If Not ComboBox1LoadTime And ComboBox1.Text.Trim <> "" Then<br />
Dim str As String<br />
Dim mdins As New mdGlobal<br />
<br />
ComboBox2.DataSource = Nothing<br />
If Not ds1 Is Nothing Then<br />
ds1.Dispose()<br />
End If<br />
<br />
str = "select iteminfo.itemid,itemname,area_item.areaid from iteminfo,area_item where iteminfo.itemid=area_item.itemid and area_item.areaid=" & ComboBox1.SelectedValue<br />
ds1 = New DataSet<br />
ds1 = mdins.GetResultFromQuery(str)<br />
<br />
ComboBox2.DataSource = ds1.Tables(0)<br />
ComboBox2.DisplayMember = "itemName"<br />
ComboBox2.ValueMember = "itemid"<br />
End If<br />
End Sub
Please take care that,in above code i use sample query and my own method for fill dataset
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Yes, thank you both very much. That sorts it. It seems to be the .datasource= nothing bit that makes it all work.
|
|
|
|
|
Hello all,I'm using VS 2003,VB.NET creating a window form application. I found problem on retrieving data from my MySQL database which have varchar and tinytext column. I found error when I try to check if any data exited by using ObjRead.Read. Anyone can give me a solution on how to check the existance of the data inside the MySQL table using VB.NET?
The following are the database table structure of the command running:
Field Type Collation Null Key Default Extra Privileges Comment<br />
------------ ----------- ----------------- ------ ------ ------- ------ ------------------------------- -------<br />
LocationCode varchar(10) latin1_swedish_ci NO PRI select,insert,update,references <br />
SettingKey varchar(10) latin1_swedish_ci NO PRI select,insert,update,references <br />
SettingValue tinytext latin1_swedish_ci YES (NULL) select,insert,update,references
The following are the Code I used to check and I'm using If Statement to control the situation:
<br />
Try 'Check Server IP<br />
Dim s As String<br />
ObjComm = New OdbcCommand("SELECT SettingValue FROM pos_setting WHERE LocationCode='" & TerminalLocate & "' AND SettingKey='Server_IP' ", ObjConn)<br />
<br />
ObjConn.Open()<br />
ObjRead = ObjComm.ExecuteReader()<br />
If ObjRead.Read Then<br />
ObjConn.Close()<br />
<br />
s = ObjRead.Item(0)<br />
If (s = 0 Or s = 1 Or Len(s) < 3 Or s = "") Then<br />
'Something run here<br />
<br />
Else<br />
<br />
End If<br />
Else<br />
MessageBox.Show("Error on Checking Server IP")<br />
End If<br />
Catch ex As Exception<br />
MessageBox.Show("Error : " + ex.Message)<br />
Finally<br />
ObjConn.Close()<br />
End Try
I have put some integer into the table:
Example: LocationCode=KK SettingKey=ServerIP SettingValue=192.168.2.80
But when I run it,it shows me this error:
Error: No data exist for the row/column.
Why could this happen? Anyone can give me some solution?
Thanks for reading.
|
|
|
|
|
Not sure - but have you tried closing your connection after you've accessed the reader and not prior to reading? A datareader needs a connection to the database to retrieve the data.
And seeing as you have a close in your finally, you do most certainly not need any more in your "if read" scope.
|
|
|
|
|
Thank you my friend. I have got it now. You get the right solution for me. I just remove the objconn.Close() in my code and everythings goes fine now. Thanks alot Alsvha~! Happy Coding my friend.
|
|
|
|
|
You are closing the connection but instead you should leave it open until you are done reading not just executing the query. You are using DataReader which is a connected class so you can only read in connected mode.
|
|
|
|
|
Thank you my CodingYoshi. I have got it now. You get the right solution for me. I just remove the objconn.Close() in my code and everythings goes fine now.Yeah,datareader problem. Thanks alot CodingYoshi~! Happy Coding my friend.
|
|
|
|
|
Are all the properties the same for different controls? Explain at least five properties of your favorite controls (e.g., what they do and how can they be used). Do not discuss 5 controls, rather 5 properties of your favorite controls.
I need help! A website somthing...second week in programming and I am LOST!
|
|
|
|
|
A property is a setting on a control, which you can set in code, or in the designer. For example, all controls have a Text property ( I believe ). But only databound controls have a Datasource property.
To answer this question, you just need to drag controls onto a form in the designer and look at what their properties are.
I'm hoping this is a middle school programming class, I'd be disgusted if a university called playing with properties in the designer a valid thing to focus on in a programming class. Second week of programming, IMO, you should not be looking at controls at all, or even windows.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian
Thank you for your help...and yes sadly this is a University class. Basic programming though.... Your responce did help.
|
|
|
|
|
OK - I'm glad I helped.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There is a GREAT definition on page 75 of our text book
Microsoft Visual Basic 2005 Step by Step
|
|
|
|
|
I'm using Visual Studio 2005 and programming in Visual Basic.
Can anyone assist me in how to Format a Cell in a TextColumn of the DataGridView Control and insert an Image in that Cell.
I want to put Images along a Row, rather than down a Column.
It is an UnBound DataGridView Control.
I understand it's all about having individual Cells Inherit the ImageType Column's Style. But I can't see how to go about it.
A code sample would be very much appreciated.
Regards, Graham
|
|
|
|
|
|
Dave,
Since posting this question, I have resolved how to display an Image in a DataGridViewTextBoxColumn.
Dim imageCell As New DataGridViewImageCell<br />
Me.DataGridView1.Item(2, 0) = imageCell<br />
Dim imageMe As New Bitmap("C:\Pictures\Graham.jpg", True)<br />
imageCell.ImageLayout = DataGridViewImageCellLayout.Stretch<br />
imageCell.Value = imageMe
That places the Image in Col 2, Row 0 and the other Rows in that Column, all accept Text input.
My problem now is to be able to do this to multiple Cells. In otherwords, reuse the variables, imageCell and imageMe as I won't know how many of these images there are until Runtime.
Any ideas on that issue please?
Regards, Graham
|
|
|
|
|
I needed to replace the disk on my development machine. Everything went fine. I had my VB.Net application backed up to DVD.
I reloaded the folder, and tried a build, I received 42 of these warning messages:
Namespace or type specified in the project-level Imports 'PegasusImaging.WinForms.TwainPro4' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
They relate to different Pegasus Namespaces (TwainPro, PrintPro, etc). I tried removing the reference, and adding it back in, but the warnings persist.
|
|
|
|
|
The only thing that would do this is your project is missing a reference or the libraries you're using haven't been reinstalled and properly registered.
|
|
|
|
|
I am working on a attendance program (for a club) that pulls the dates (all of them) for a member from a database. I know how to display all of the dates but I was wondering if it is possible to group by week? For example, you have 3 dates (i.e. 05/07/2008, 05/08,2008, 05/09/2008) from last week and two dates from the current week (i.e. 05/11/2008, 05/12/2008) and wish to display them like:
05/07/2008 05/08/2008 05/09/20085/
05/11/2008 05/12/2008
and not like:
05/07/2008
05/08/2008
05/09/2009
05/11/2008
05/12/2008
Thanks for the help in advance!
|
|
|
|
|
The DateTime class has a DayOfWeek property. you can display your data anyway you'd like, are you asking how to work out which days are in the same week, or how to display that data ? What are you using to display it now ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I want to display which days are in the same week. I am using a SQL statement to pull the attendance information from a database on a server but just want to group the attendance records into weekly groups. I am throwing the information into a list box.
|
|
|
|
|
OK - so this is a SQL question. I am not sure how to do it in your query, if you don't have the day of week already. I recommend asking in the SQL forum.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Try this, daetpart is your friend - from BOL
SELECT
DATEPART(wk,datadate) Week,
COUNT(*) Attendees
FROM MyTable
WHERE DATEPART(YEAR,datadate) = 2008
GROUP BY
DATEPART(wk,datadate)
ORDER BY DATEPART(wk,datadate)
Never underestimate the power of human stupidity
RAH
|
|
|
|