Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: Network File Path Problem Pin
Kevin Marois21-Nov-16 4:43
professionalKevin Marois21-Nov-16 4:43 
QuestionHow To Refactor This Pin
Kevin Marois18-Nov-16 4:48
professionalKevin Marois18-Nov-16 4:48 
AnswerRe: How To Refactor This Pin
Pete O'Hanlon18-Nov-16 5:41
mvePete O'Hanlon18-Nov-16 5:41 
GeneralRe: How To Refactor This Pin
Kevin Marois18-Nov-16 6:03
professionalKevin Marois18-Nov-16 6:03 
GeneralRe: How To Refactor This Pin
Gerry Schmitz18-Nov-16 7:49
mveGerry Schmitz18-Nov-16 7:49 
GeneralRe: How To Refactor This Pin
Kevin Marois18-Nov-16 9:03
professionalKevin Marois18-Nov-16 9:03 
GeneralRe: How To Refactor This Pin
Gerry Schmitz18-Nov-16 10:44
mveGerry Schmitz18-Nov-16 10:44 
QuestionSaving Datagridview Pin
Member 1285691017-Nov-16 12:23
Member 1285691017-Nov-16 12:23 
hello,

i really need help, i have created a dynamic datagridview, which the number of rows i write it in a xml file. When i save it for first time, in the xml file write the correct number of rows but when i save it again the "new" xml file write zero rows! i can understand why. i try to use datatable and dataset but nothing the problem is that datagridview hasnt rows.

Please some idies?

Thank you

public Form1(int cntC, int cntL)
{
InitializeComponent();
Create_dGV(cntC, cntL);
}


private void Create_dGV(int cnt, int cnt2)
{
for (int i = 0; i < cnt; i++)
{
CmbBx();

}

for (int i = dGV.RowCount; i < cnt2; i++)
{
dGV.Rows.Add();
}

for (int i = 0; i < dGV.Rows.Count; i++)
{

dGV.DefaultCellStyle.NullValue = " ";
dGV.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

}
dGV.AllowUserToAddRows = false;

}

private void CmbBx()
{
DataGridViewComboBoxColumn CmbBx = new DataGridViewComboBoxColumn();
List<string> data = new List<string>();
data.Add("0");
data.Add("3");
data.Add("5");
data.Add("9");
CmbBx.DataSource = data;
CmbBx.Width = 120;
CmbBx.FlatStyle = FlatStyle.Flat;
dGV.Columns.Add(CmbBx);

}

private void SaveBttn_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();

{
for (int j = 0; j < dGV.ColumnCount; j++)
{
dt.Columns.Add((j).ToString(), typeof(String));
}

for (int i = 0; i < dGV.RowCount; i++)
{
DataRow d = new DataRow();
d = dt.NewRow();

for (int j = 0; j < dGV.ColumnCount; j++)
{

d[j] = dGV.Rows[i].Cells[j].Value;
}
dt.Rows.Add(d);
}
}

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
using (XmlWriter writer = XmlWriter.Create(name, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("dGV");
{
writer.WriteElementString("ColumnsCount", dt.Columns.Count.ToString());
writer.WriteElementString("RowsCount", dt.Rows.Count.ToString());
for (int i = 0; i < dt.Columns.Count; i++)
{
//string lttr= "a"+ i.ToString();
//writer.WriteStartElement(lttr);
//{
// for (int j = 0; j < dt.Rows.Count; j++)
// {
// lttr= "a"+ i.ToString()+ j.ToString();
// writer.WriteElementString(lttr, dt.Rows[j][i].ToString());

// }
//}
//writer.WriteEndElement();

}
}

writer.WriteEndElement();
writer.WriteEndDocument();
}
}
// other form
private void OpenBttn_Click(object sender, EventArgs e)
{
XmlDocument xDoc = new XmlDocument();

xDoc.Load(name);
int C, R;
string hlps, hlps2;

hlps = xDoc.SelectSingleNode("dGV / ColumnsCount").InnerText;
C = Int32.Parse(hlps);
hlps = xDoc.SelectSingleNode("dGV / RowssCount").InnerText;
R = Int32.Parse(hlps);
Form1 f = new Form1(C, R);

}
}
}

modified 18-Nov-16 4:54am.

AnswerRe: Saving Datagridview Pin
Dave Kreskowiak17-Nov-16 13:00
mveDave Kreskowiak17-Nov-16 13:00 
QuestionWinForm Installation Config files directory .. Pin
JP9017-Nov-16 6:05
JP9017-Nov-16 6:05 
AnswerRe: WinForm Installation Config files directory .. Pin
OriginalGriff17-Nov-16 6:38
mveOriginalGriff17-Nov-16 6:38 
Questionenquary Pin
Ramesh_sahu16-Nov-16 22:22
Ramesh_sahu16-Nov-16 22:22 
AnswerRe: enquary PinPopular
Richard MacCutchan16-Nov-16 22:27
mveRichard MacCutchan16-Nov-16 22:27 
GeneralRe: enquary Pin
Pete O'Hanlon16-Nov-16 22:55
mvePete O'Hanlon16-Nov-16 22:55 
GeneralRe: enquary Pin
Richard MacCutchan16-Nov-16 23:23
mveRichard MacCutchan16-Nov-16 23:23 
AnswerRe: enquary Pin
Pete O'Hanlon16-Nov-16 23:01
mvePete O'Hanlon16-Nov-16 23:01 
GeneralRe: enquary Pin
Mycroft Holmes16-Nov-16 23:05
professionalMycroft Holmes16-Nov-16 23:05 
GeneralRe: enquary Pin
OriginalGriff16-Nov-16 23:11
mveOriginalGriff16-Nov-16 23:11 
GeneralRe: enquary Pin
Pete O'Hanlon17-Nov-16 0:42
mvePete O'Hanlon17-Nov-16 0:42 
AnswerRe: enquary Pin
ZurdoDev17-Nov-16 1:11
professionalZurdoDev17-Nov-16 1:11 
AnswerRe: enquary PinPopular
V.17-Nov-16 2:55
professionalV.17-Nov-16 2:55 
AnswerRe: enquary Pin
Gerry Schmitz17-Nov-16 5:22
mveGerry Schmitz17-Nov-16 5:22 
QuestionDual Screen Display Pin
Member 972228316-Nov-16 0:59
Member 972228316-Nov-16 0:59 
AnswerRe: Dual Screen Display Pin
OriginalGriff16-Nov-16 1:40
mveOriginalGriff16-Nov-16 1:40 
GeneralRe: Dual Screen Display Pin
Member 972228316-Nov-16 2:20
Member 972228316-Nov-16 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.