|
Meh, saves my poor fingers from wearing down with extraneous key-strokes. Besides makes the transition to JavaScript easier
|
|
|
|
|
Hello,
I have a problem...
In designer I have set data source to "subjektBindingSource" (without "").
Then on click on a button I delete a selected row from a database, and it works ok, but my datagridview doesn't show the changes...
<br />
SqlConnection conn = new SqlConnection();<br />
<br />
conn.ConnectionString = connStr;<br />
String naredbaSql = null;<br />
naredbaSql = "DELETE from Subjekt WHERE ID = " + idUser;<br />
<br />
conn.Open();<br />
<br />
SqlCommand comand = new SqlCommand(naredbaSql, conn);<br />
comand.ExecuteNonQuery(); <br />
<br />
conn.Close();<br />
<br />
So, all I want is to refresh my datagridview so it shows data from database without that row I erased. I tried with Refresh and Update methods, but it doesn't work...
can you help me?
Thank you,
Niksa
|
|
|
|
|
Check where you are binding your datagridview
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
Hy,
I'm really new to C# programming and I have a few problems with data binding.
I am building a Windows application.
I have two tables in my database and they are related.
First table is named Author (and has these fields: AuthorID, AuthorName),
and the other one is named Books (BooksID, AuthorID -> this is a Foreign Key, and BookTitle).
My question is: How can I (using a form) change the data in my database?
I have found a lot of tutorials, but they didn't really helped me. All they suggest is that I can relate tables on a form by dragging AuthorName from the Author table on AuthorID from the Books table. But if I do that, Authors are displayed in combobox so I can't enter a new author if I want to enter new data...
I know that I probably made it sound really confusing, so I apologize in advance
Thanks
|
|
|
|
|
Alessandra77 wrote: I'm really new to C# programming
Alessandra77 wrote: I have two tables in my database and they are related.
If you're REALLY new, then you're probably diving in a little too deep.
Alessandra77 wrote: How can I (using a form) change the data in my database?
Your form should ideally just display the data, and call a middle tier that knows about books and authors, and which then calls a data layer that knows how to persist your data to the DB.
There's two UI approachs to take, one is to show your data in a grid and support entering new data which is then saved, the other is to have a seperate form that shows your fields and you enter them to have them entered into your DB.
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 )
|
|
|
|
|
Thanks for your help, I'll try to do what you suggested...
|
|
|
|
|
I have built a custom message box form (Windows form), on this form I have a label which displays a message that gets passed in to the message box. My question is how can I resize the label and form based on the text passed in? if a large block of text is passed in, the form and label need to resize to be able to show all the text and not just cut it off.
thanks for help
|
|
|
|
|
Check out this for measuring a string (in pixels) http://msdn2.microsoft.com/en-us/library/403ezxd2(VS.80).aspx[^]
Just use MeasureString on your string, and it will return the width and height of the text, which you can then use to resize your label and form. Hopefully
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi,
set label.AutoSize true so the label grows and shrinks automatically,
then set label.Text, now get label.Size and adapt form.Size accordingly.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I have built a custom gradient form as part of a windows control library. What I would like to do is to hide the BackColor property from the forms designer (since it has now been replaced by BackColor1 and BackColor2). Currently when I create a new inherited form which inherits from my GradientForm in the designer pane I can see BackColor, BackColor1, and BackColor2. With a windows control I would use something like the following to remove BackColor:
internal class GradientPanelDesigner : ScrollableControlDesigner
{
public GradientPanelDesigner()
{
}
protected override void PreFilterProperties(System.Collections.IDictionary properties)
{
properties.Remove("BackColor");
properties.Remove("BackgroundImage");
}
}
Is there an equivalent for a Windows Form?
thanks for help
|
|
|
|
|
Hello,
i have a combobox binded in the xaml code to an xml file:
<stackpanel.resources>
<xmldataprovider>
x:Key="AufgabenlisteXml"
XPath="Aufgaben/Fachgebiet"
Source=".\Aufgabenliste.xml">
<combobox horizontalalignment="Left" x:name="ComboBoxFach" selectedindex="1">
DataContext="{StaticResource AufgabenlisteXml}"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True">
<combobox.itemtemplate>
<datatemplate>
<textblock text="{Binding XPath=@FachName}">
The ComboBox works fine, but when i try to use the selected value in my Code i just get back an empty string.
Code i tried:
String new = ComboBoxFach.Text.ToString();
or
String new = ComboBoxFach.SelectedValue.ToString();
Other propertys of the ComboBox can be read. For example the SelectedIndex is shown correctly.
I think the problem is cause of the data binding cause i`m new to these concept.
Hope someone can help.
Thanks for answers.
|
|
|
|
|
What about SelectedItem.ToString() ?
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Selected.Item.ToString returns System.Xml.XmlElement - and i have no Idea how to convert this.
|
|
|
|
|
Well, the selected item is an XmlElement so how about:
XmlElement elem = comboBox.SelectedItem as XmlElement;
and then you can use elem.<property> to get whatever information your after. Like it's name for example.
So perhaps:
XmlElement elem = comboBox.SelectedItem as XmlElement;<br />
String myString = elem.Name;
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Thanks for your help.
Works great.
|
|
|
|
|
Hello everyone,
What is the most convenient way to check whether elapsed time from some time point to another time point is larger than 2 seconds?
Currently, I am using TimeSpan, and I am using stupid method to check hour/minute/second one by one to decide. Are there any quick way to check?
thanks in advance,
George
|
|
|
|
|
Just use TotalSeconds:
DateTime start = ???;
DateTime now = ???;
TimeSpan difference = now-start;
if(difference.TotalSeconds > 2)
more that two seconds longer
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Cool, SK!
regards,
George
|
|
|
|
|
Hi,
DateTime check=DateTime.Now.AddSeconds(2);
...
if(DateTime.Now>check) doSomething();
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Cool, Luc!
regards,
George
|
|
|
|
|
<br />
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch() ;<br />
<br />
timer.Reset() ;
timer.Start() ;<br />
<br />
<br />
timer.Stop() ;<br />
<br />
|
|
|
|
|
|
I find it easier to use.
But read the documentation. It has greater precision which may not be important in this case, but maybe down the line you'll find you need it.
|
|
|
|
|
Cool, thanks PIEBALDconsult!
regards,
George
|
|
|
|
|
Is it possible to somehow draw text on an image with an inverted color? I basically want to make a small timestamp that always shows up, and I don't want to resort to putting it in a colored rectangle if I can avoid it.
I've got access to framework 3.5 if that helps.
|
|
|
|