well i think it's important to start this thred...
so let's start with my bugs on my program
i have created program for entering future students into high school (it's version for my high school)...now i have a form with dataGridView control and with 3 buttons...
one button is for displaying table into dataGridView using code for XML...
second button is for erasing row in that table when i select specific row and the third button is for printing that table using default computer printer
now the problem is when i'm working in program and i enter values for example 3 rows i want to sort them by clicking last column named "Bodovi", program gives me error message like "if you want to continue working with program press continue and if you want to stop program press quit"
but when i press continue program erase everything in table even rows i've created...how can i fix it??? can i fix it by changing some property on dataGridView or something else??? i really need your help
6 replies to this topic
#1
Posted 07 March 2011 - 12:57 PM
|
|
|
#2
Posted 07 March 2011 - 04:33 PM
Are you using the default datagridview method to sort by clicking the header of a column? If I remember correctly, to do so you need to set the property AllowUserToAddRow to False, else it crashes. If that's not the problem, as I doubt it is. You should post the faulty code here because your problem description is vague.
#3
Posted 07 March 2011 - 04:36 PM
Double post, sorry.
Edited by wixifo, 08 March 2011 - 07:42 AM.
#4
Posted 08 March 2011 - 02:45 AM
but if i set the property AllowUserToAddRow to false then program will not create a new row when you enter first character in first columns??? tell me if i'm wrong...i don't want that because it's cool that program automatically creates a new row at some point...
#5
Posted 08 March 2011 - 02:57 AM
and i don't have a code for sorting...i've been searching for that code for a longer then a month and i didn't find...i only found the code for sorting 2 or 3 rows in a table but i didn't find the code for sorting unknown number of rows so it's done automatically in visual C# 2010 express edition
if it will help i will give you code for XML
and for calling that XML into dataGridView control so that XML can be shown as table
XML code
this is calling XML inside C# by button
this is properties of that form
AllowUserToAddRows = True
AllowUserToDeleteRows = True
AllowUserToOrderColumns = False
if i set property AllowUserToDeleteRows to False will i be able to delete selected rows with this button:
if it will help i will give you code for XML
and for calling that XML into dataGridView control so that XML can be shown as table
XML code
<?xml version="1.0" encoding="utf-8" ?> <Ime> <Tehničar_za_računalstvo> <Ime> </Ime> <Prezime> </Prezime> <Datum_Rođenja> </Datum_Rođenja> <Učeni_Jezik> </Učeni_Jezik> <Religijski_Predmet> </Religijski_Predmet> <Dodatni_Bodovi> </Dodatni_Bodovi> <Br_Dod_Bodova> </Br_Dod_Bodova> <Matematika_7> </Matematika_7> <Matematika_8> </Matematika_8> <Hrvatski_7> </Hrvatski_7> <Hrvatski_8> </Hrvatski_8> <Strani_Jezik_7> </Strani_Jezik_7> <Strani_Jezik_8> </Strani_Jezik_8> <Fizika_7> </Fizika_7> <Fizika_8> </Fizika_8> <Teh_Kultura_7> </Teh_Kultura_7> <Teh_Kultura_8> </Teh_Kultura_8> <Prosjek_7> </Prosjek_7> <Prosjek_8> </Prosjek_8> <Ponavljač> </Ponavljač> <Bodovi> </Bodovi> </Tehničar_za_računalstvo> </Ime>parts inside <Tehničar_za_računalstvo> will be columns and i want sort rows by "Bodovi" column
this is calling XML inside C# by button
private void button1_Click_1(object sender, EventArgs e)
{
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml("C:\\EtsDtb\\EtsDtb\\bin\\Debug\\Teh_za_rac.xml");
DataSet ds = new DataSet("Tablica");
ds = xmlDatadoc.DataSet;
Tablica1.DataSource = ds.DefaultViewManager;
Tablica1.DataMember = "Tehničar_za_računalstvo";
}
after i click that button, table will be shown in dataGridViewthis is properties of that form
AllowUserToAddRows = True
AllowUserToDeleteRows = True
AllowUserToOrderColumns = False
if i set property AllowUserToDeleteRows to False will i be able to delete selected rows with this button:
private void button3_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in Tablica1.SelectedRows)
try
{
Tablica1.Rows.Remove(row);
}
catch (Exception)
{
MessageBox.Show("Nije moguće obrisati red");
}
}
#6
Posted 08 March 2011 - 07:35 AM
I thought you were adding rows with a form, like I said, the problem lies with the default sort method datagridview offers, it tries to sort every row, but it includes the last row, the one to add a row, it causes it to crash, you can test by adding some values programmatically and setting allowusertoaddrow to false to see if it's really the problem. What you can do is write your own sort method.
#7
Posted 08 March 2011 - 09:34 AM
i don't know how to write my own method for sorting...like i said it's my first project
could there be any changes if i insted
AllowUserToOrderColumns = False
set the property to
AllowUserToOrderColumns = True
could there be any changes if i insted
AllowUserToOrderColumns = False
set the property to
AllowUserToOrderColumns = True
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









