Click here to Skip to main content
15,891,951 members
Home / Discussions / C#
   

C#

 
AnswerRe: Add control to form ,from UserControl Pin
Shuaib wasif khan1-Nov-10 1:50
Shuaib wasif khan1-Nov-10 1:50 
GeneralRe: Add control to form ,from UserControl Pin
Said Ali Jalali2-Nov-10 23:53
Said Ali Jalali2-Nov-10 23:53 
QuestionHow to use Get Post in C# Pin
Sonu J30-Oct-10 20:38
Sonu J30-Oct-10 20:38 
AnswerRe: How to use Get Post in C# Pin
Abhinav S31-Oct-10 0:02
Abhinav S31-Oct-10 0:02 
AnswerRe: How to use Get Post in C# Pin
Eddy Vluggen31-Oct-10 0:05
professionalEddy Vluggen31-Oct-10 0:05 
AnswerRe: How to use Get Post in C# Pin
Ravi Bhavnani31-Oct-10 16:33
professionalRavi Bhavnani31-Oct-10 16:33 
AnswerRe: How to use Get Post in C# Pin
VarunSharma432-Nov-10 20:44
professionalVarunSharma432-Nov-10 20:44 
QuestionPopulate c# datastructure from table or view [modified] Pin
Michael Pauli30-Oct-10 14:48
Michael Pauli30-Oct-10 14:48 
Hi!

There must be a smarter way to do this! This is about if I can bind a simple datastructure to a table.

Problem: I want to hold an instance of a (simple) datastructure - say a List<t> or a Collection or similar - I don't care - representing the contents of a view or table - say view. How to impl. that the most natural/generic way?

My solution:

// Fill DataTable.
DataTable dt = new DataTable();
string strConn = "Data Source=MyPC\\SQLExpress; Initial Catalog=MyDBInst; Integrated Security=True; User ID=; Password=;";
SqlConnection con = new SqlConnection(strConn);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM v_SomeViewOfMine", con);
da.Fill(dt);

// Populate List.
List<testclass> my_list = new List<testclass>();
foreach(DataRow dr in dt.Rows)
my_list.Add(new TestClass(
(string)dr.ItemArray[0],
(int)dr.ItemArray[1],
(int)dr.ItemArray[2],
(int)dr.ItemArray[3]));
con.Close();

Where constructor TestClass is:

public TestClass(string s, int a, int b, int c)
{ Name = s; Category = a; Conference = b; SubCategory = c; }

This approch works - "all is fine" and list is fine! Or is it? I feel that I miss some binding michanism-thingy like (pseudo):

List<testclass> my_list = new List<testclass>();
my_list.BindToDataTable(dt);
my_list.SetBindingColumn("Name", "Name", Type.string);
my_list.SetBindingColumn("Category", "Category", Type.int);
my_list.SetBindingColumn("Conference", "Conference", Type.int);
my_list.SetBindingColumn("Sub category", "SubCategory", Type.int);

Inspired from how one would setup a DataGrid in a xaml (< DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />).

So in other words: Do I have to iterate the DataTable myself (dealing with dr.ItemArray[] typed object) or can I bind it to a datastructure in some way?

Thank's in advance.
Michael Mogensen
modified on Saturday, October 30, 2010 8:56 PM

AnswerRe: Populate c# datastructure from table or view Pin
Karthik. A30-Oct-10 15:59
Karthik. A30-Oct-10 15:59 
QuestionResizing form according to the screen resolution Pin
Nouman Bhatti29-Oct-10 22:03
Nouman Bhatti29-Oct-10 22:03 
AnswerRe: Resizing form according to the screen resolution Pin
OriginalGriff29-Oct-10 22:31
mveOriginalGriff29-Oct-10 22:31 
GeneralRe: Resizing form according to the screen resolution Pin
Michael Pauli30-Oct-10 14:55
Michael Pauli30-Oct-10 14:55 
GeneralRe: Resizing form according to the screen resolution Pin
OriginalGriff30-Oct-10 20:53
mveOriginalGriff30-Oct-10 20:53 
AnswerRe: Resizing form according to the screen resolution Pin
Eddy Vluggen31-Oct-10 0:14
professionalEddy Vluggen31-Oct-10 0:14 
AnswerRe: Resizing form according to the screen resolution Pin
fjdiewornncalwe31-Oct-10 9:40
professionalfjdiewornncalwe31-Oct-10 9:40 
Questiondatagridview KeyDown event doesnt working Pin
Erdinc2729-Oct-10 21:45
Erdinc2729-Oct-10 21:45 
AnswerRe: datagridview KeyDown event doesnt working Pin
Richard MacCutchan29-Oct-10 22:45
mveRichard MacCutchan29-Oct-10 22:45 
GeneralRe: datagridview KeyDown event doesnt working Pin
Erdinc2730-Oct-10 1:14
Erdinc2730-Oct-10 1:14 
GeneralRe: datagridview KeyDown event doesnt working Pin
Dave Kreskowiak30-Oct-10 9:02
mveDave Kreskowiak30-Oct-10 9:02 
GeneralRe: datagridview KeyDown event doesnt working Pin
Richard MacCutchan30-Oct-10 9:28
mveRichard MacCutchan30-Oct-10 9:28 
AnswerRe: datagridview KeyDown event doesnt working Pin
Michael Pauli30-Oct-10 15:14
Michael Pauli30-Oct-10 15:14 
GeneralRe: datagridview KeyDown event doesnt working Pin
Erdinc273-Nov-10 0:24
Erdinc273-Nov-10 0:24 
Questionproblem related to "Nural networks face detection algprithm" Pin
inayathussaintoori29-Oct-10 15:07
inayathussaintoori29-Oct-10 15:07 
AnswerNural networks Repost Pin
Richard MacCutchan29-Oct-10 22:34
mveRichard MacCutchan29-Oct-10 22:34 
AnswerRe: problem related to "Nural networks face detection algprithm" Pin
Dave Kreskowiak30-Oct-10 8:59
mveDave Kreskowiak30-Oct-10 8:59 

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.