Click here to Skip to main content
15,917,568 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataTable output to string with filter Pin
Blubbo17-Apr-15 9:49
Blubbo17-Apr-15 9:49 
Updated code... Seems to be working... Any suggestion for a better approach?
C#
DataTable dataTable = new DataTable();

dataTable.Columns.Add("Variable", typeof(string));
dataTable.Columns.Add("Hex Value", typeof(Int64));
dataTable.Columns.Add("Value", typeof(string));
dataTable.Columns.Add("Hide", typeof(bool));

dataTable.Rows.Add("Ronald", 0x0, "Value = 0", false);
dataTable.Rows.Add("Ronald", 0x1, "Value = 1", true);
dataTable.Rows.Add("Ronald", 0x2, "Value = 2", false);
dataTable.Rows.Add("Ronald", 0x4, "Value = 4", true);
dataTable.Rows.Add("Ronald", 0x8, "Value = 8", false);
dataTable.Rows.Add("Ronald", 0x16, "Value = 16", false);
dataTable.Rows.Add("Ronald", 0x32, "Value = 32", false);
dataTable.Rows.Add("Ronald", 0x64, "Value = 64", true);
dataTable.Rows.Add("Ronald", 0x128, "Value = 128", false);
dataTable.Rows.Add("Ronald", 0xFF, "Value = 255", true);

try
{
     DataRow selectedRow = dataTable.Select("").FirstOrDefault(x => (Int64)x["Hex Value"] == Convert.ToInt64(tb_Input.Text, 16));
     lbl_Result.Text = selectedRow["Value"].ToString();
}
catch
{
     lbl_Result.Text = "Unknown";
}

DataRow[] drArrRow = dataTable.Select("Hide = False");
DataTable filteredDataTable = new DataTable();

filteredDataTable.Columns.Add("Variable", typeof(string));
filteredDataTable.Columns.Add("Value", typeof(string));

foreach (DataRow dr in drArrRow)
{
    filteredDataTable.Rows.Add(dr["Variable"], dr["Value"]);
}

string res = String.Join(Environment.NewLine, filteredDataTable.Rows.OfType<DataRow>().Select(x => String.Join(" ; ", x.ItemArray)));

MessageBox.Show(res);

GeneralRe: DataTable output to string with filter Pin
Sascha Lefèvre17-Apr-15 9:53
professionalSascha Lefèvre17-Apr-15 9:53 
GeneralRe: DataTable output to string with filter Pin
Blubbo17-Apr-15 9:56
Blubbo17-Apr-15 9:56 
GeneralRe: DataTable output to string with filter Pin
Sascha Lefèvre17-Apr-15 11:52
professionalSascha Lefèvre17-Apr-15 11:52 
AnswerRe: DataTable output to string with filter Pin
Sascha Lefèvre17-Apr-15 10:26
professionalSascha Lefèvre17-Apr-15 10:26 
GeneralRe: DataTable output to string with filter Pin
Blubbo20-Apr-15 1:52
Blubbo20-Apr-15 1:52 
GeneralRe: DataTable output to string with filter Pin
Sascha Lefèvre20-Apr-15 1:57
professionalSascha Lefèvre20-Apr-15 1:57 
QuestionTime delay without freezing the GUI Pin
Member 1085025317-Apr-15 5:24
Member 1085025317-Apr-15 5:24 
AnswerRe: Time delay without freezing the GUI Pin
OriginalGriff17-Apr-15 5:46
mveOriginalGriff17-Apr-15 5:46 
GeneralRe: Time delay without freezing the GUI Pin
PIEBALDconsult17-Apr-15 6:46
mvePIEBALDconsult17-Apr-15 6:46 
GeneralRe: Time delay without freezing the GUI Pin
Member 1085025317-Apr-15 7:03
Member 1085025317-Apr-15 7:03 
GeneralRe: Time delay without freezing the GUI Pin
Sascha Lefèvre17-Apr-15 7:37
professionalSascha Lefèvre17-Apr-15 7:37 
GeneralRe: Time delay without freezing the GUI Pin
Eddy Vluggen17-Apr-15 8:23
professionalEddy Vluggen17-Apr-15 8:23 
AnswerRe: Time delay without freezing the GUI Pin
Richard MacCutchan17-Apr-15 5:46
mveRichard MacCutchan17-Apr-15 5:46 
QuestionLock client application (controlled) on call for Form Pin
Member 998884817-Apr-15 4:03
Member 998884817-Apr-15 4:03 
AnswerRe: Lock client application (controlled) on call for Form Pin
Dave Kreskowiak17-Apr-15 4:11
mveDave Kreskowiak17-Apr-15 4:11 
GeneralRe: Lock client application (controlled) on call for Form Pin
Member 998884817-Apr-15 4:19
Member 998884817-Apr-15 4:19 
GeneralRe: Lock client application (controlled) on call for Form Pin
Dave Kreskowiak17-Apr-15 4:24
mveDave Kreskowiak17-Apr-15 4:24 
QuestionHow to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471216-Apr-15 22:42
Member 1099471216-Apr-15 22:42 
AnswerRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
OriginalGriff16-Apr-15 23:16
mveOriginalGriff16-Apr-15 23:16 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471216-Apr-15 23:29
Member 1099471216-Apr-15 23:29 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon16-Apr-15 23:40
mvePete O'Hanlon16-Apr-15 23:40 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
OriginalGriff16-Apr-15 23:43
mveOriginalGriff16-Apr-15 23:43 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Pete O'Hanlon16-Apr-15 23:54
mvePete O'Hanlon16-Apr-15 23:54 
GeneralRe: How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]' Pin
Member 1099471217-Apr-15 0:36
Member 1099471217-Apr-15 0:36 

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.