|
Depending on where the new row is added, you can use a RowDoubleClick or Click event to process the data in that field. For example, if the row is added to the end of the data grid, you can use a collection of the rows and access the last element of the collection array directly.
Then, you could systematically go through the cells you want to extract the data out of by passing the column name to one of the functions provided by the data grid class (something like SelectedIndex() or Index() and then you pass the name of the column).
Hope this helps.
|
|
|
|
|
i already know about that... but i really need to put a button in a cell. but thanx anyway...
|
|
|
|
|
Oh, sorry. Didn't understand what you meant. Good luck!
|
|
|
|
|
I'm creating a control and don't want it to be resizable. Most people say to hide it from the designer and throw an error when it's called, but I can't do that because the Size property isn't overrideable! Right now I set the size back the the default height and width in the resize event, but this may be confusing to the user as it looks resizable.
Thanks,
Nick
|
|
|
|
|
|
Thanks! I ran the example code there through a translator and found out you use the shadows keyword.
|
|
|
|
|
great
|
|
|
|
|
|
|
You can easily fix a controls size by overriding SetBoundsCore. It looks like this.
Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As System.Windows.Forms.BoundsSpecified)
Const fixedWidth As Integer = 50
Const fixedHeight As Integer = 50
MyBase.SetBoundsCore(x, y, fixedWidth, fixedHeight, specified)
End Sub
I know changing the size back in the resize event will also work, but doing it that way actually allows the control's size to be changed and then it quickly changes it back. Overriding SetBoundsCore will prevent the change from ever occurring.
|
|
|
|
|
hi All
i have a textbox that sometimes Should be Null and my table field is Nullable. When the textbox has no Entry i want to put Null in my Field.
thanks
Vuyiswa
|
|
|
|
|
Then check the Text property on the text box. If it is an empty string String.Empty then put null (DBNull.Value ) in your column, otherwise put the value of the Text property in.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Thanks you For your reply.
i understand the Logic, if the textbox is Empty string the set it to Null, but code wise i dont understand. please post me a skeleton code to learn from it.
Thanks Colin
Vuyiswa
|
|
|
|
|
If textbox.text = nothing then
field = "Null"
End If
Just make sure you replace textbox and field .
You also might want to use textbox.text.trim to remove any whitespace on the ends of the text to help 'idiotproof' it.
|
|
|
|
|
Hi when i run my code it tells me "Cant Store Null in Extension Field" , but my table does Accept Null in that Field.
Here is the code in my save Button for Field Extension.
Dim newRow As DataRow = DataSet11._PROPERTY.NewRow<br />
'newRow("Num_key") = CStr(txtnumkey.Text)<br />
If txtextension.Text.Empty.Trim = Nothing Then<br />
newRow("Extension") = "Null"<br />
Else<br />
newRow("Extension") = txtextension.Text<br />
End If<br />
-- modified at 10:51 Monday 2nd July, 2007
Vuyiswa
|
|
|
|
|
Here's a problem:
If txtextension.Text.Empty.Trim = Nothing Then
You don't want txtExtension.Text.Empty. That returns nothing itself, so the condition will always be true. You just need txtextension.Text.Trim , which returns the textbox's text with now whitespace at the ends.
|
|
|
|
|
i have remove the Empty keyword. and when i try to save in the dataset,
it Gives me this Error
<br />
unable to Add the Record<br />
System.FormatException:Input string was not a Correct Format.<br />
at System.Number.Parse(string s,NumberStyles style,NumberFormatifno info)<br />
at system.int32.Parse(string s,NumberStype style,IFormatProvider provider)<br />
at System.String.system.IConvertible.Toint32(IFormatProvider Provider)<br />
at system.convert.Toint32(Object Value)<br />
at System.Data.Common.Int32Storage.Set(int32 record,Object Value)<br />
at System.DataCoulmn.set_Item(int32 record,Object Value) couldnt store<Null> in Extension Column. Expected type int32<br /> .
Please Sir Remember that my Field is numeric and it Allow Null, and in my Field there is a Default that i bind to the Table for Null Values if there is none and the table Defination is Nullable.
Thanks
Vuyiswa
|
|
|
|
|
The table is numeric. While it may allow a null value, it doesn't allow "null" as a string, which is what I was telling you to do. Instead of using
If txtextension.Text.Empty.Trim = Nothing Then<br />
newRow("Extension") = "Null"<br />
Else
you can set the row to something like -1, 0, nothing, or another default value you choose. You can also set it to dbnull.value
|
|
|
|
|
Aren't you looking to put DbNull.Value in there instead of the string "Null"??
|
|
|
|
|
Well Dave you Solved the Problem, here is a Complete Code
<br />
Dim newRow As DataRow = DataSet11._PROPERTY.NewRow<br />
newRow("Num_key") = CStr(txtnumkey.Text)<br />
If txtextension.Text.Trim = Nothing Then<br />
newRow("Extension") = DBNull.Value<br />
Else<br />
newRow("Extension") = txtextension.Text<br />
End If<br />
and Now i have i have to save the Dataset to the Database by with the Update method. here is my code
<br />
Dim strErrorMsg As String<br />
Dim strerror As System.Data.SqlClient.SqlError<br />
'save the datasource Changes<br />
If mblnIsDirty Then<br />
If MessageBox.Show("Do you want to Save the Changes?", "Property", _<br />
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then<br />
' Checking for Error in the dataset<br />
Try<br />
SqlDataAdapter1.Update(DataSet11, "Property")<br />
Catch<br />
MessageBox.Show("Error saving Data in the DataBase", "Property")<br />
<br />
End Try<br />
End If<br />
End If<br />
if i try to update, it Brings
<br />
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll<br />
<br />
Additional information: Missing SourceTable mapping: 'Property'<br />
-- modified at 12:02 Monday 2nd July, 2007
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: SqlDataAdapter1.Update(DataSet11, "Property")
Apparently, you don't have a datatable in DataSet11 (very bad name by the way), called "Property".
|
|
|
|
|
Thanks Dave for your time.
yes i know that the Table "Property" named i used is very Bad, but its the name of the table, sometimes to find my way around in my code i had to prefix it with an underscore, because Property is a keyword in VB. i have redefined the Dataset11 and it does not give an error anymore, but still the data does not reflect in my table.
<br />
Dim strErrorMsg As String<br />
Dim strerror As System.Data.SqlClient.SqlError<br />
'save the datasource Changes<br />
If mblnIsDirty Then<br />
If MessageBox.Show("Do you want to Save the Changes?", "Property", _<br />
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then<br />
' Checking for Error in the dataset<br />
Try<br />
<br />
SqlDataAdapter1.Update(DataSet11, "Property")<br />
Catch ExSQL As System.Data.SqlClient.SqlException<br />
MessageBox.Show(strErrorMsg, "SQL Server Error: " & strerror.Number, MessageBoxButtons.OK, MessageBoxIcon.Error)<br />
End Try<br />
End If<br />
End If<br />
let me find a way out of this, if i dont i will shout
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: yes i know that the Table "Property" named i used is very Bad,
No, I said the name of the DataSet object is very bad.
Vuyiswamb wrote: sometimes to find my way around in my code i had to prefix it with an underscore, because Property is a keyword in VB.
So? "Property" isn't used to describe a .NET object anywhere in your code. It's just the name of a DataTable, which is perfectly legal.
Vuyiswamb wrote: but still the data does not reflect in my table.
You're going to have to step through the update code and look at the values of variables so you know what your code is thinking. Perhaps that "dirty" variable isn't set? Perhaps there are no changes in the "Property" table in your DataSet?
|
|
|
|
|
Sorry About that Dave, the Update method was working just that there was Data comming into my table, so after inserting new records , when i checked the last Record, it was not what i used for testing. so i searched them and i found them
Thank you Dave for you time. let me Paste my update code for user who will have the same Problem. here is the Solution.
<br />
If mblnIsDirty Then<br />
If MessageBox.Show("Do you want to Save the Changes?", "Property", _<br />
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then<br />
<br />
<br />
If checkerrors() Then<br />
MessageBox.Show("Your Dataset has Errors")<br />
Else<br />
SqlDataAdapter1.Update(DataSet11, "Property")<br />
End If<br />
<br />
End If<br />
End If<br />
here is the CheckErrors() function code
<br />
Private Function checkerrors() As Boolean<br />
<br />
<br />
Dim table As Data.DataTable<br />
Dim row As Data.DataRow<br />
SqlDataAdapter1.Update(DataSet11, "Property")<br />
If DataSet11.HasErrors Then<br />
<br />
For Each table In DataSet11.Tables<br />
If table.HasErrors Then<br />
Return True<br />
For Each row In table.Rows<br />
If row.HasErrors Then<br />
MessageBox.Show("Dataset has Errors")<br />
' Process error here.<br />
<br />
End If<br />
Next<br />
ElseIf table.HasErrors = False Then<br />
Return False<br />
MessageBox.Show("Dataset has no Errors")<br />
End If<br />
Next<br />
End If<br />
End Function<br />
Thanks for your time and Help
Vuyiswa
|
|
|
|
|
So if i choose '0' will it Show in the '0' table? i need it to show Null. how can i do that one
Vuyiswa
Vuyiswa
|
|
|
|
|